Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special className to style boolean cells (checkbox) in Vanilla package #1865

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});