Skip to content

Commit

Permalink
Use an own class for React Vanilla checkboxes
Browse files Browse the repository at this point in the history
Use 'control.checkbox' instead of the generic 'control.input' class
to ease the customization of the React Vanilla checkboxes.
  • Loading branch information
andresgutgon authored Jan 13, 2022
1 parent e9400b6 commit 5b123ce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/vanilla/src/cells/BooleanCell.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
The MIT License
Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -32,7 +32,7 @@ import {
import { withJsonFormsCellProps } from '@jsonforms/react';
import { StatelessComponent } from 'react';
import { VanillaRendererProps } from '../index';
import { withVanillaCellProps } from '../util/index';
import { withVanillaBooleanCellProps } from '../util/index';

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

export default withJsonFormsCellProps(withVanillaCellProps(BooleanCell));
export default withJsonFormsCellProps(withVanillaBooleanCellProps(BooleanCell));
4 changes: 4 additions & 0 deletions packages/vanilla/src/styles/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const vanillaStyles: StyleDef[] = [
name: 'control.select',
classNames: ['select']
},
{
name: 'control.checkbox',
classNames: ['checkbox']
},
{
name: 'control.radio',
classNames: ['radio']
Expand Down
4 changes: 4 additions & 0 deletions packages/vanilla/src/util/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ export const withVanillaEnumCellProps = withVanillaCellPropsForType(
'control.select'
);

export const withVanillaBooleanCellProps = withVanillaCellPropsForType(
'control.checkbox'
);

17 changes: 16 additions & 1 deletion packages/vanilla/test/renderers/BooleanCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const fixture = {
name: 'control',
classNames: ['control']
},
{
name: 'control.checkbox',
classNames: ['checkbox']
},
{
name: 'control.validation',
classNames: ['validation']
Expand Down Expand Up @@ -240,7 +244,7 @@ describe('Boolean cell', () => {
</JsonFormsStateProvider>
);
const input = wrapper.find('input');
expect(input.hasClass('input')).toBe(true);
expect(input.hasClass('checkbox')).toBe(true);
expect(input.hasClass('validate')).toBe(true);
expect(input.hasClass('valid')).toBe(true);
});
Expand Down Expand Up @@ -381,4 +385,15 @@ describe('Boolean cell', () => {
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.disabled).toBe(false);
});

test('with checkbox className', () => {
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
wrapper = mount(
<JsonFormsStateProvider initState={{ renderers: vanillaRenderers, core }}>
<BooleanCell schema={fixture.schema} uischema={fixture.uischema} path='foo' />
</JsonFormsStateProvider>
);
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.classList.contains('checkbox')).toBe(true);
});
});

0 comments on commit 5b123ce

Please sign in to comment.