Skip to content

Commit

Permalink
Add special className to style boolean cells (checkbox) in Vanilla
Browse files Browse the repository at this point in the history
package
  • Loading branch information
andresgutgon committed Jan 10, 2022
1 parent 075bbc4 commit 9277648
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 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'
);

15 changes: 15 additions & 0 deletions 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 @@ -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 9277648

Please sign in to comment.