Skip to content

Commit 79adb32

Browse files
authored
fix(tasty): improve caching (#290)
1 parent 1c574e2 commit 79adb32

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

.changeset/cyan-masks-hunt.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add an `inputStyles` prop to the `CheckboxGroup` component to customize styles of a checkbox group itself.
6+
Improve Tasty caching.

src/components/forms/Checkbox/CheckboxGroup.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { useProviderProps } from '../../../provider';
77
import { FormContext, useFormProps } from '../Form/Form';
88
import {
99
BaseProps,
10-
BLOCK_STYLES,
10+
CONTAINER_STYLES,
11+
ContainerStyleProps,
1112
extractStyles,
12-
OUTER_STYLES,
13+
Styles,
1314
tasty,
1415
} from '../../../tasty';
1516
import { FieldWrapper } from '../FieldWrapper';
@@ -29,7 +30,6 @@ const WRAPPER_STYLES = {
2930
'': '1fr',
3031
'has-sider': 'max-content 1fr',
3132
},
32-
placeItems: 'baseline start',
3333
};
3434

3535
const CheckGroupElement = tasty({
@@ -52,8 +52,10 @@ const CheckGroupElement = tasty({
5252
export interface CubeCheckboxGroupProps
5353
extends BaseProps,
5454
AriaCheckboxGroupProps,
55-
FormFieldProps {
55+
FormFieldProps,
56+
ContainerStyleProps {
5657
orientation?: 'vertical' | 'horizontal';
58+
inputStyles?: Styles;
5759
}
5860

5961
function CheckboxGroup(props: WithNullableValue<CubeCheckboxGroupProps>, ref) {
@@ -78,19 +80,19 @@ function CheckboxGroup(props: WithNullableValue<CubeCheckboxGroupProps>, ref) {
7880
requiredMark = true,
7981
tooltip,
8082
labelSuffix,
83+
inputStyles,
8184
...otherProps
8285
} = props;
8386
let domRef = useDOMRef(ref);
8487

85-
let styles = extractStyles(otherProps, OUTER_STYLES, WRAPPER_STYLES);
86-
let groupStyles = extractStyles(otherProps, BLOCK_STYLES);
88+
let styles = extractStyles(otherProps, CONTAINER_STYLES, WRAPPER_STYLES);
8789

8890
let state = useCheckboxGroupState(props);
8991
let { groupProps, labelProps } = useCheckboxGroup(props, state);
9092

9193
let radioGroup = (
9294
<CheckGroupElement
93-
styles={groupStyles}
95+
styles={inputStyles}
9496
mods={{
9597
horizontal: orientation === 'horizontal',
9698
}}

src/tasty/tasty.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,18 @@ function tasty<K extends StyleList, C = Record<string, unknown>>(
192192
styles = undefined;
193193
}
194194

195+
const propStylesCacheKey = JSON.stringify(propStyles);
196+
const stylesCacheKey = useMemo(() => {
197+
return JSON.stringify(styles);
198+
}, [styles]);
199+
195200
const useDefaultStyles = !propStyles && !styles;
201+
196202
const styleCacheKey = useMemo(() => {
197203
return `${styles ? JSON.stringify(styles) : ''}.${
198204
propStyles ? JSON.stringify(propStyles) : ''
199205
}`;
200-
}, [propStyles, styles]);
206+
}, [propStylesCacheKey, stylesCacheKey]);
201207

202208
let allStyles: Styles = useMemo(
203209
() =>

0 commit comments

Comments
 (0)