Skip to content

Commit 5b123ce

Browse files
authored
Use an own class for React Vanilla checkboxes
Use 'control.checkbox' instead of the generic 'control.input' class to ease the customization of the React Vanilla checkboxes.
1 parent e9400b6 commit 5b123ce

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

packages/vanilla/src/cells/BooleanCell.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2017-2019 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -32,7 +32,7 @@ import {
3232
import { withJsonFormsCellProps } from '@jsonforms/react';
3333
import { StatelessComponent } from 'react';
3434
import { VanillaRendererProps } from '../index';
35-
import { withVanillaCellProps } from '../util/index';
35+
import { withVanillaBooleanCellProps } from '../util/index';
3636

3737
export const BooleanCell: StatelessComponent<CellProps> =
3838
(props: CellProps & VanillaRendererProps) => {
@@ -59,4 +59,4 @@ export const BooleanCell: StatelessComponent<CellProps> =
5959
*/
6060
export const booleanCellTester: RankedTester = rankWith(2, isBooleanControl);
6161

62-
export default withJsonFormsCellProps(withVanillaCellProps(BooleanCell));
62+
export default withJsonFormsCellProps(withVanillaBooleanCellProps(BooleanCell));

packages/vanilla/src/styles/styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export const vanillaStyles: StyleDef[] = [
5353
name: 'control.select',
5454
classNames: ['select']
5555
},
56+
{
57+
name: 'control.checkbox',
58+
classNames: ['checkbox']
59+
},
5660
{
5761
name: 'control.radio',
5862
classNames: ['radio']

packages/vanilla/src/util/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,7 @@ export const withVanillaEnumCellProps = withVanillaCellPropsForType(
209209
'control.select'
210210
);
211211

212+
export const withVanillaBooleanCellProps = withVanillaCellPropsForType(
213+
'control.checkbox'
214+
);
215+

packages/vanilla/test/renderers/BooleanCell.test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const fixture = {
5454
name: 'control',
5555
classNames: ['control']
5656
},
57+
{
58+
name: 'control.checkbox',
59+
classNames: ['checkbox']
60+
},
5761
{
5862
name: 'control.validation',
5963
classNames: ['validation']
@@ -240,7 +244,7 @@ describe('Boolean cell', () => {
240244
</JsonFormsStateProvider>
241245
);
242246
const input = wrapper.find('input');
243-
expect(input.hasClass('input')).toBe(true);
247+
expect(input.hasClass('checkbox')).toBe(true);
244248
expect(input.hasClass('validate')).toBe(true);
245249
expect(input.hasClass('valid')).toBe(true);
246250
});
@@ -381,4 +385,15 @@ describe('Boolean cell', () => {
381385
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
382386
expect(input.disabled).toBe(false);
383387
});
388+
389+
test('with checkbox className', () => {
390+
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
391+
wrapper = mount(
392+
<JsonFormsStateProvider initState={{ renderers: vanillaRenderers, core }}>
393+
<BooleanCell schema={fixture.schema} uischema={fixture.uischema} path='foo' />
394+
</JsonFormsStateProvider>
395+
);
396+
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
397+
expect(input.classList.contains('checkbox')).toBe(true);
398+
});
384399
});

0 commit comments

Comments
 (0)