Skip to content

Commit

Permalink
fix: correctly scope checkboxes and radios in classy to avoid conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC committed Nov 27, 2024
1 parent 75dc858 commit cd52f5a
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 27 deletions.
7 changes: 4 additions & 3 deletions system/core/scripts/generateComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ class CssComponentBuilder extends ComponentBuilder {
const propsType = omitVariants ? 'Omit<Props, "data-variant">' : 'Props';
const props = this.buildProps(fixedPropsArg);
const classNameProp = props.find(({ key }) => key === 'className');
const append: string[] = [
`className: ${classNameProp ? `'${classNameProp.value}'` : 'undefined'}`
];
if (!classNameProp) {
throw new Error(`Missing className prop for ${displayName || varName}`);
}
const append: string[] = [`className: '${classNameProp.value}'`];
const additionalProps = props.filter(({ key }) => key !== 'className');
if (additionalProps.length) {
append.push(
Expand Down
1 change: 1 addition & 0 deletions system/core/src/components/Checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OptionalKeys, css } from '../utils';

export const element = 'input';
export const selectors = ['input[type="checkbox"]:not(.toggle)'];
export const className = 'checkbox';

export interface Props {
type: 'checkbox';
Expand Down
2 changes: 1 addition & 1 deletion system/core/src/components/InputWithIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const fullStyles = css`
& > [data-mode='input-append'] {
height: calc(var(--tk-input-height) - var(--tk-input-border-width) * 2);
width: calc(
var(--tk-input-icon-size)+ var(--tk-input-icon-gap)+
var(--tk-input-icon-size) + var(--tk-input-icon-gap) +
var(--tk-input-icon-end-padding)
);
--tk-icon-button-padding: 8px !important;
Expand Down
2 changes: 1 addition & 1 deletion system/core/src/components/InputWithPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const fullStyles = css`
grid-area: 1/4/1/5;
height: calc(var(--tk-input-height) - var(--tk-input-border-width) * 2);
width: calc(
var(--tk-input-icon-size)+ var(--tk-input-icon-gap)+
var(--tk-input-icon-size) + var(--tk-input-icon-gap) +
var(--tk-input-icon-end-padding)
);
--tk-icon-button-padding: 8px !important;
Expand Down
1 change: 1 addition & 0 deletions system/core/src/components/Radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OptionalKeys, css } from '../utils';

export const element = 'input';
export const selectors = ['input[type="radio"]:not(.toggle)'];
export const className = 'radio';

export interface Props {
type: 'radio';
Expand Down
2 changes: 1 addition & 1 deletion system/core/src/components/TextAreaWithIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const fullStyles = css`
& > [data-mode='input-append'] {
height: calc(var(--tk-input-height) - var(--tk-input-border-width) * 2);
width: calc(
var(--tk-input-icon-size)+ var(--tk-input-icon-gap)+
var(--tk-input-icon-size) + var(--tk-input-icon-gap) +
var(--tk-input-icon-end-padding)
);
--tk-icon-button-padding: 8px !important;
Expand Down
2 changes: 1 addition & 1 deletion system/core/src/components/TextAreaWithPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const fullStyles = css`
grid-area: 1/4/1/5;
height: calc(var(--tk-input-height) - var(--tk-input-border-width) * 2);
width: calc(
var(--tk-input-icon-size)+ var(--tk-input-icon-gap)+
var(--tk-input-icon-size) + var(--tk-input-icon-gap) +
var(--tk-input-icon-end-padding)
);
--tk-icon-button-padding: 8px !important;
Expand Down
7 changes: 6 additions & 1 deletion system/css/src/buildFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export class ComponentBuilder extends CssFileBuilder<ComponentFileContent> {

getClassySelectors() {
const { element, className, selectors = [] } = this.fileContent;
if (!className) return selectors;
if (!className) {
console.warn(
`className is missing in ${this.folderName}/${this.fileName}`
);
return selectors;
}
if (element === 'input') return [`input.${className}`];
return [`.${className}`];
}
Expand Down
2 changes: 1 addition & 1 deletion system/react-css/src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const Checkbox = buildWithComponent<
>({
tag: 'input',
displayName: 'Checkbox',
className: undefined,
className: 'checkbox',
additionalProps: { type: checkbox.defaultProps.type as never }
});
2 changes: 1 addition & 1 deletion system/react-css/src/components/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const Radio = buildWithComponent<
>({
tag: 'input',
displayName: 'Radio',
className: undefined,
className: 'radio',
additionalProps: { type: radio.defaultProps.type as never }
});
15 changes: 15 additions & 0 deletions system/react-css/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* DO NOT EDIT: This file is generated in the post-build step of @tablecheck/tablekit-core
* If you need to provide more "structure" to this component move it to the 'structuredComponents' folder
*/
import { tooltip } from '@tablecheck/tablekit-core';
import * as React from 'react';

import { buildWithComponent } from '../utils';

export type Props = tooltip.Props & React.HTMLAttributes<HTMLSpanElement>;

export const Tooltip = buildWithComponent<
HTMLSpanElement,
Props & React.HTMLAttributes<HTMLSpanElement>
>({ tag: 'span', displayName: 'Tooltip', className: 'tooltip' });
4 changes: 2 additions & 2 deletions system/react-css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export { TextAreaWithSuffix } from './components/TextAreaWithSuffix';
export type { Props as TextAreaWithSuffixProps } from './components/TextAreaWithSuffix';
export { Toggle } from './components/Toggle';
export type { Props as ToggleProps } from './components/Toggle';
export { Tooltip } from './components/Tooltip';
export type { Props as TooltipProps } from './components/Tooltip';
export {
AlertCore,
AlertTitle,
Expand Down Expand Up @@ -100,5 +102,3 @@ export {
useTablekitTheme,
ThemeProvider
} from './structuredComponents/ThemeProvider';
export { Tooltip } from './structuredComponents/Tooltip';
export type { Props as TooltipProps } from './structuredComponents/Tooltip';
15 changes: 0 additions & 15 deletions system/react-css/src/structuredComponents/Tooltip.tsx

This file was deleted.

0 comments on commit cd52f5a

Please sign in to comment.