From ff27e63b5da195c5056469ace3845eabac48cf88 Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Mon, 10 Jan 2022 13:02:50 +0100 Subject: [PATCH] Add special className to style boolean cells (checkbox) in Vanilla package --- packages/vanilla/src/cells/BooleanCell.tsx | 12 ++++++------ packages/vanilla/src/styles/styles.ts | 4 ++++ packages/vanilla/src/util/index.tsx | 4 ++++ .../vanilla/test/renderers/BooleanCell.test.tsx | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/vanilla/src/cells/BooleanCell.tsx b/packages/vanilla/src/cells/BooleanCell.tsx index 03490d1f8..bea9e3806 100644 --- a/packages/vanilla/src/cells/BooleanCell.tsx +++ b/packages/vanilla/src/cells/BooleanCell.tsx @@ -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 @@ -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 = (props: CellProps & VanillaRendererProps) => { @@ -59,4 +59,4 @@ export const BooleanCell: StatelessComponent = */ export const booleanCellTester: RankedTester = rankWith(2, isBooleanControl); -export default withJsonFormsCellProps(withVanillaCellProps(BooleanCell)); +export default withJsonFormsCellProps(withVanillaBooleanCellProps(BooleanCell)); diff --git a/packages/vanilla/src/styles/styles.ts b/packages/vanilla/src/styles/styles.ts index b950b139d..e0b5dd91a 100644 --- a/packages/vanilla/src/styles/styles.ts +++ b/packages/vanilla/src/styles/styles.ts @@ -53,6 +53,10 @@ export const vanillaStyles: StyleDef[] = [ name: 'control.select', classNames: ['select'] }, + { + name: 'control.checkbox', + classNames: ['checkbox'] + }, { name: 'control.radio', classNames: ['radio'] diff --git a/packages/vanilla/src/util/index.tsx b/packages/vanilla/src/util/index.tsx index da8dcc3a7..34dbee072 100644 --- a/packages/vanilla/src/util/index.tsx +++ b/packages/vanilla/src/util/index.tsx @@ -209,3 +209,7 @@ export const withVanillaEnumCellProps = withVanillaCellPropsForType( 'control.select' ); +export const withVanillaBooleanCellProps = withVanillaCellPropsForType( + 'control.checkbox' +); + diff --git a/packages/vanilla/test/renderers/BooleanCell.test.tsx b/packages/vanilla/test/renderers/BooleanCell.test.tsx index 96314c50e..cae273766 100644 --- a/packages/vanilla/test/renderers/BooleanCell.test.tsx +++ b/packages/vanilla/test/renderers/BooleanCell.test.tsx @@ -54,6 +54,10 @@ const fixture = { name: 'control', classNames: ['control'] }, + { + name: 'control.checkbox', + classNames: ['checkbox'] + }, { name: 'control.validation', classNames: ['validation'] @@ -240,7 +244,7 @@ describe('Boolean cell', () => { ); 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); }); @@ -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( + + + + ); + const input = wrapper.find('input').getDOMNode() as HTMLInputElement; + expect(input.classList.contains('checkbox')).toBe(true); + }); });