@a-type/ui 3.0.22 → 3.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cjs/components/box/Box.d.ts +0 -3
  2. package/dist/cjs/components/box/Box.js +6 -13
  3. package/dist/cjs/components/box/Box.js.map +1 -1
  4. package/dist/cjs/components/card/Card.d.ts +3 -2
  5. package/dist/cjs/components/card/Card.js +7 -5
  6. package/dist/cjs/components/card/Card.js.map +1 -1
  7. package/dist/cjs/components/contextMenu/contextMenu.js +2 -2
  8. package/dist/cjs/components/contextMenu/contextMenu.js.map +1 -1
  9. package/dist/cjs/components/dialog/Dialog.js +2 -2
  10. package/dist/cjs/components/dialog/Dialog.js.map +1 -1
  11. package/dist/cjs/components/dropdownMenu/DropdownMenu.js +2 -2
  12. package/dist/cjs/components/dropdownMenu/DropdownMenu.js.map +1 -1
  13. package/dist/cjs/components/layouts/PageNav.js +2 -2
  14. package/dist/cjs/components/layouts/PageNav.js.map +1 -1
  15. package/dist/cjs/components/layouts/PageNowPlaying.js +2 -2
  16. package/dist/cjs/components/layouts/PageNowPlaying.js.map +1 -1
  17. package/dist/cjs/components/popover/Popover.js +2 -2
  18. package/dist/cjs/components/popover/Popover.js.map +1 -1
  19. package/dist/cjs/components/select/Select.js +2 -2
  20. package/dist/cjs/components/select/Select.js.map +1 -1
  21. package/dist/cjs/components/tooltip/Tooltip.js +2 -3
  22. package/dist/cjs/components/tooltip/Tooltip.js.map +1 -1
  23. package/dist/cjs/systems/GroupScale.d.ts +838 -0
  24. package/dist/cjs/systems/GroupScale.js +27 -0
  25. package/dist/cjs/systems/GroupScale.js.map +1 -0
  26. package/dist/css/main.css +2 -2
  27. package/dist/esm/components/box/Box.d.ts +0 -3
  28. package/dist/esm/components/box/Box.js +6 -12
  29. package/dist/esm/components/box/Box.js.map +1 -1
  30. package/dist/esm/components/card/Card.d.ts +3 -2
  31. package/dist/esm/components/card/Card.js +7 -5
  32. package/dist/esm/components/card/Card.js.map +1 -1
  33. package/dist/esm/components/contextMenu/contextMenu.js +2 -2
  34. package/dist/esm/components/contextMenu/contextMenu.js.map +1 -1
  35. package/dist/esm/components/dialog/Dialog.js +2 -2
  36. package/dist/esm/components/dialog/Dialog.js.map +1 -1
  37. package/dist/esm/components/dropdownMenu/DropdownMenu.js +2 -2
  38. package/dist/esm/components/dropdownMenu/DropdownMenu.js.map +1 -1
  39. package/dist/esm/components/layouts/PageNav.js +2 -2
  40. package/dist/esm/components/layouts/PageNav.js.map +1 -1
  41. package/dist/esm/components/layouts/PageNowPlaying.js +2 -2
  42. package/dist/esm/components/layouts/PageNowPlaying.js.map +1 -1
  43. package/dist/esm/components/popover/Popover.js +2 -2
  44. package/dist/esm/components/popover/Popover.js.map +1 -1
  45. package/dist/esm/components/select/Select.js +2 -2
  46. package/dist/esm/components/select/Select.js.map +1 -1
  47. package/dist/esm/components/tooltip/Tooltip.js +2 -3
  48. package/dist/esm/components/tooltip/Tooltip.js.map +1 -1
  49. package/dist/esm/systems/GroupScale.d.ts +838 -0
  50. package/dist/esm/systems/GroupScale.js +20 -0
  51. package/dist/esm/systems/GroupScale.js.map +1 -0
  52. package/package.json +1 -1
  53. package/src/components/box/Box.tsx +11 -30
  54. package/src/components/card/Card.tsx +52 -28
  55. package/src/components/contextMenu/contextMenu.tsx +3 -3
  56. package/src/components/dialog/Dialog.tsx +3 -3
  57. package/src/components/dropdownMenu/DropdownMenu.tsx +3 -3
  58. package/src/components/layouts/PageNav.tsx +2 -4
  59. package/src/components/layouts/PageNowPlaying.tsx +3 -3
  60. package/src/components/popover/Popover.tsx +3 -3
  61. package/src/components/select/Select.tsx +3 -3
  62. package/src/components/tooltip/Tooltip.tsx +3 -5
  63. package/src/systems/GroupScale.tsx +35 -0
@@ -0,0 +1,20 @@
1
+ // @unocss-include
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext } from 'react';
4
+ export const GroupScaleContext = createContext(1);
5
+ const GROUP_SCALE_NESTING_FACTOR = 0.75;
6
+ export const GroupScaleLayer = ({ children }) => {
7
+ const current = useGroupScale();
8
+ return (_jsx(GroupScaleContext.Provider, { value: current * GROUP_SCALE_NESTING_FACTOR, children: children }));
9
+ };
10
+ export function useGroupScale() {
11
+ return useContext(GroupScaleContext);
12
+ }
13
+ export function useGroupScaleStyles(composeStyles) {
14
+ const scale = useGroupScale();
15
+ return Object.assign({ '--spacing-scale': scale, '--local-corner-scale': scale }, composeStyles);
16
+ }
17
+ export const GroupScaleReset = ({ children }) => {
18
+ return (_jsx(GroupScaleContext.Provider, { value: 1, children: children }));
19
+ };
20
+ //# sourceMappingURL=GroupScale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupScale.js","sourceRoot":"","sources":["../../../src/systems/GroupScale.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAA4B,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAS,CAAC,CAAC,CAAC;AAE1D,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAA4B,EAAE,EAAE;IACzE,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,OAAO,CACN,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,GAAG,0BAA0B,YACrE,QAAQ,GACmB,CAC7B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,aAAa;IAC5B,OAAO,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,aAA6B;IAChE,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;IAC9B,uBACC,iBAAiB,EAAE,KAAK,EACxB,sBAAsB,EAAE,KAAK,IAC1B,aAAa,EACf;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IACxE,OAAO,CACN,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,CAAC,YAClC,QAAQ,GACmB,CAC7B,CAAC;AACH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-type/ui",
3
- "version": "3.0.22",
3
+ "version": "3.0.24",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "url": "https://github.com/a-type/ui"
@@ -1,5 +1,10 @@
1
1
  import clsx from 'clsx';
2
- import { createContext, Ref, useContext, useMemo } from 'react';
2
+ import { Ref } from 'react';
3
+ import {
4
+ GroupScaleLayer,
5
+ GroupScaleReset,
6
+ useGroupScaleStyles,
7
+ } from '../../systems/GroupScale.js';
3
8
  import { PaletteName } from '../../uno/index.js';
4
9
  import { SlotDiv, SlotDivProps } from '../utility/SlotDiv.js';
5
10
 
@@ -84,16 +89,7 @@ export function Box({
84
89
  ref,
85
90
  ...rest
86
91
  }: BoxProps) {
87
- const { spacingScale } = useContext(BoxContext);
88
-
89
- const style = useMemo(
90
- () => ({
91
- ...userStyle,
92
- '--spacing-scale': container === 'reset' ? 1 : spacingScale,
93
- '--local-corner-scale': container === 'reset' ? 1 : `${spacingScale}`,
94
- }),
95
- [userStyle, spacingScale, container],
96
- );
92
+ const style = useGroupScaleStyles(userStyle);
97
93
 
98
94
  const items = itemsSolo ?? align?.split(' ')[0];
99
95
  const justify = justifySolo ?? align?.split(' ')[1];
@@ -220,26 +216,11 @@ export function Box({
220
216
  );
221
217
 
222
218
  if (container || p) {
223
- return (
224
- <BoxContext.Provider
225
- value={{
226
- spacingScale:
227
- container === 'reset'
228
- ? 1
229
- : spacingScale * SPACING_SCALE_NESTING_FACTOR,
230
- }}
231
- >
232
- {main}
233
- </BoxContext.Provider>
234
- );
219
+ if (container === 'reset') {
220
+ return <GroupScaleReset>{main}</GroupScaleReset>;
221
+ }
222
+ return <GroupScaleLayer>{main}</GroupScaleLayer>;
235
223
  }
236
224
 
237
225
  return main;
238
226
  }
239
-
240
- const SPACING_SCALE_NESTING_FACTOR = 0.75;
241
- export const BoxContext = createContext<{
242
- spacingScale: number;
243
- }>({
244
- spacingScale: 1,
245
- });
@@ -1,7 +1,17 @@
1
1
  import { Slot } from '@radix-ui/react-slot';
2
2
  import classNames from 'clsx';
3
- import { HTMLAttributes, MouseEvent, ReactNode, Ref } from 'react';
3
+ import {
4
+ CSSProperties,
5
+ HTMLAttributes,
6
+ MouseEvent,
7
+ ReactNode,
8
+ Ref,
9
+ } from 'react';
4
10
  import { withClassName, withProps } from '../../hooks.js';
11
+ import {
12
+ GroupScaleLayer,
13
+ useGroupScaleStyles,
14
+ } from '../../systems/GroupScale.js';
5
15
  import { Box } from '../box/Box.js';
6
16
  import { Masonry, MasonryProps } from '../masonry/masonry.js';
7
17
  import { SlotDiv } from '../utility/SlotDiv.js';
@@ -18,6 +28,8 @@ export function CardMain({
18
28
  compact,
19
29
  nonInteractive,
20
30
  ref,
31
+ style,
32
+ children,
21
33
  ...rest
22
34
  }: {
23
35
  asChild?: boolean;
@@ -29,47 +41,59 @@ export function CardMain({
29
41
  nonInteractive?: boolean;
30
42
  visuallyFocused?: boolean;
31
43
  visuallyDisabled?: boolean;
44
+ style?: CSSProperties;
32
45
  ref?: Ref<any>;
33
46
  }) {
34
47
  const isInteractive = !nonInteractive && (!!asChild || !!rest.onClick);
35
48
  const Comp = asChild ? Slot : isInteractive ? 'button' : 'div';
49
+
50
+ const scaleStyles = useGroupScaleStyles(style);
51
+
36
52
  return (
37
- <Comp
38
- ref={ref}
39
- className={classNames(
40
- 'layer-components:(flex flex-col items-start gap-1 transition pb-2 flex-1 min-h-40px bg-transparent border-none text-start text-inherit text-sm relative z-1 p-0 font-inherit outline-none rounded-t-lg)',
41
- !!compact && 'layer-variants:(pb-0)',
42
- isInteractive &&
43
- classNames(
44
- 'layer-components:cursor-pointer',
45
- 'layer-components:hover:(bg-black/10 color-black)',
46
- 'layer-components:focus:outline-none',
47
- 'layer-components:focus-visible:(outline-none bg-black/10 ring-inset ring-4 ring-accent)',
48
- 'layer-components:[&[data-visually-focused=true]]:(bg-black/10 ring-inset ring-4 ring-accent)',
49
- 'layer-components:disabled:(cursor-default)',
50
- 'layer-components:[&[data-visually-disabled=true]]:(cursor-default)',
51
- ),
52
- className,
53
- )}
54
- data-compact={compact}
55
- data-visually-focused={rest.visuallyFocused}
56
- data-visually-disabled={rest.visuallyDisabled}
57
- data-interactive={isInteractive}
58
- {...rest}
59
- />
53
+ <GroupScaleLayer>
54
+ <Comp
55
+ ref={ref}
56
+ className={classNames(
57
+ 'layer-components:(flex flex-col items-start gap-1 transition pb-xs flex-1 min-h-40px bg-transparent)',
58
+ 'layer-components:(border-none text-start text-inherit text-sm relative z-1 p-0 font-inherit outline-none rounded-t-md)',
59
+ !!compact && 'layer-variants:(pb-0)',
60
+ isInteractive &&
61
+ classNames(
62
+ 'layer-components:cursor-pointer',
63
+ 'layer-components:hover:(bg-black/10 color-black)',
64
+ 'layer-components:focus:outline-none',
65
+ 'layer-components:focus-visible:(outline-none bg-black/10 ring-inset ring-4 ring-accent)',
66
+ 'layer-components:[&[data-visually-focused=true]]:(bg-black/10 ring-inset ring-4 ring-accent)',
67
+ 'layer-components:disabled:(cursor-default)',
68
+ 'layer-components:[&[data-visually-disabled=true]]:(cursor-default)',
69
+ ),
70
+ className,
71
+ )}
72
+ data-compact={compact}
73
+ data-visually-focused={rest.visuallyFocused}
74
+ data-visually-disabled={rest.visuallyDisabled}
75
+ data-interactive={isInteractive}
76
+ style={scaleStyles}
77
+ {...rest}
78
+ >
79
+ {children}
80
+ </Comp>
81
+ </GroupScaleLayer>
60
82
  );
61
83
  }
62
84
 
63
85
  export const CardTitle = withClassName(
64
86
  'div',
65
- 'layer-components:(flex flex-col gap-1 mt-0 bg-white py-2 px-3 rounded-lg rounded-bl-none rounded-tr-none w-auto mr-auto border border-solid border-gray-dark/50 border-t-none border-l-none text-md max-h-80px overflow-hidden text-ellipsis max-w-full text-inherit font-semibold relative z-1 transition-colors)',
66
- 'layer-components:[[data-compact=true]_&]:(py-1 text-sm)',
87
+ 'layer-components:(flex flex-col gap-1 my-xs mx-xs py-xs px-sm w-auto max-h-80px max-w-full relative z-1)',
88
+ 'layer-components:(bg-white rounded-md border border-solid border-gray-dark transition-colors)',
89
+ 'layer-components:(text-md overflow-hidden text-ellipsis text-inherit font-semibold)',
90
+ 'layer-components:[[data-compact=true]_&]:(text-sm)',
67
91
  );
68
92
 
69
93
  const CardContentRoot = withClassName(
70
94
  'div',
71
- 'layer-components:(flex flex-col gap-1 px-2 py-1 bg-white/80 color-black rounded-md mx-2 my-0.5 border border-solid border-gray-dark/50 text-xs relative z-1)',
72
- 'layer-variants:[[data-compact=true]_&]:(py-0 px-1 my-0 text-xs)',
95
+ 'layer-components:(flex flex-col gap-1 px-2 py-1 bg-white/80 color-black rounded-sm mx-2 my-0.5 border border-solid border-gray-dark/50 text-xs relative z-1)',
96
+ 'layer-variants:[[data-compact=true]_&]:(py-0 px-sm my-0 text-xs)',
73
97
  'layer-variants:[&[data-unstyled=true]]:(p-0 [background:unset] border-none)',
74
98
  );
75
99
  export interface CardContentProps extends HTMLAttributes<HTMLDivElement> {
@@ -2,7 +2,7 @@ import * as ContextMenuPrimitive from '@radix-ui/react-context-menu';
2
2
  import classNames from 'clsx';
3
3
  import { ComponentPropsWithoutRef } from 'react';
4
4
  import { withClassName } from '../../hooks/withClassName.js';
5
- import { BoxContext } from '../box/Box.js';
5
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
6
6
 
7
7
  export const ContextMenuRoot = ContextMenuPrimitive.Root;
8
8
 
@@ -16,7 +16,7 @@ export const ContextMenuContent = function Content({
16
16
  }) {
17
17
  return (
18
18
  <ContextMenuPrimitive.Portal>
19
- <BoxContext.Provider value={{ spacingScale: 1 }}>
19
+ <GroupScaleReset>
20
20
  <ContextMenuPrimitive.Content
21
21
  className={classNames(
22
22
  'layer-components:(min-w-120px bg-white rounded-md overflow-hidden border-gray-dark border shadow-md z-menu)',
@@ -35,7 +35,7 @@ export const ContextMenuContent = function Content({
35
35
  alignOffset={-10}
36
36
  {...props}
37
37
  />
38
- </BoxContext.Provider>
38
+ </GroupScaleReset>
39
39
  </ContextMenuPrimitive.Portal>
40
40
  );
41
41
  };
@@ -14,7 +14,7 @@ import {
14
14
  import { useMediaQuery } from '../../hooks/useMediaQuery.js';
15
15
  import useMergedRef from '../../hooks/useMergedRef.js';
16
16
  import { withClassName } from '../../hooks/withClassName.js';
17
- import { BoxContext } from '../box/Box.js';
17
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
18
18
  import { Button } from '../button/index.js';
19
19
  import { Icon } from '../icon/Icon.js';
20
20
  import { useParticles } from '../particles/index.js';
@@ -160,7 +160,7 @@ export const Content = function Content({
160
160
  return (
161
161
  <DialogPrimitive.Portal>
162
162
  <StyledOverlay />
163
- <BoxContext.Provider value={{ spacingScale: 1 }}>
163
+ <GroupScaleReset>
164
164
  <StyledContent
165
165
  data-dialog-content
166
166
  {...bind(props)}
@@ -184,7 +184,7 @@ export const Content = function Content({
184
184
  {!disableSheet && <DialogSwipeHandle />}
185
185
  {children}
186
186
  </StyledContent>
187
- </BoxContext.Provider>
187
+ </GroupScaleReset>
188
188
  </DialogPrimitive.Portal>
189
189
  );
190
190
  };
@@ -3,8 +3,8 @@ import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
3
3
  import classNames, { clsx } from 'clsx';
4
4
  import { Ref } from 'react';
5
5
  import { withClassName } from '../../hooks/withClassName.js';
6
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
6
7
  import { PaletteName } from '../../uno/index.js';
7
- import { BoxContext } from '../box/Box.js';
8
8
  import { SlotDiv } from '../utility/SlotDiv.js';
9
9
  import { DropdownTriggerProvider } from './DropdownTriggerContext.js';
10
10
 
@@ -13,9 +13,9 @@ const StyledContent = withClassName(
13
13
  props: DropdownMenuPrimitive.DropdownMenuContentProps,
14
14
  ) {
15
15
  return (
16
- <BoxContext.Provider value={{ spacingScale: 1 }}>
16
+ <GroupScaleReset>
17
17
  <DropdownMenuPrimitive.Content {...props} />
18
- </BoxContext.Provider>
18
+ </GroupScaleReset>
19
19
  );
20
20
  },
21
21
  'layer-components:(min-w-220px bg-white z-menu shadow-lg rounded-md border border-gray-dark flex flex-col)',
@@ -3,7 +3,7 @@
3
3
  import classNames from 'clsx';
4
4
  import { HTMLAttributes, useRef } from 'react';
5
5
  import { useBoundsCssVars } from '../../hooks.js';
6
- import { BoxContext } from '../box/Box.js';
6
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
7
7
  import { HideWhileKeyboardOpen } from '../utility/HideWhileKeyboardOpen.js';
8
8
 
9
9
  export function PageNav({
@@ -31,9 +31,7 @@ export function PageNav({
31
31
  )}
32
32
  ref={ref}
33
33
  >
34
- <BoxContext.Provider value={{ spacingScale: 1 }}>
35
- {children}
36
- </BoxContext.Provider>
34
+ <GroupScaleReset>{children}</GroupScaleReset>
37
35
  </HideWhileKeyboardOpen>
38
36
  );
39
37
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import classNames from 'clsx';
4
4
  import { HTMLAttributes } from 'react';
5
- import { BoxContext } from '../box/Box.js';
5
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
6
6
  import { useConfig } from '../provider/Provider.js';
7
7
 
8
8
  export function PageNowPlaying({
@@ -17,7 +17,7 @@ export function PageNowPlaying({
17
17
  const { virtualKeyboardBehavior } = useConfig();
18
18
 
19
19
  return (
20
- <BoxContext.Provider value={{ spacingScale: 1 }}>
20
+ <GroupScaleReset>
21
21
  <div
22
22
  {...props}
23
23
  className={classNames(
@@ -39,6 +39,6 @@ export function PageNowPlaying({
39
39
  className,
40
40
  )}
41
41
  />
42
- </BoxContext.Provider>
42
+ </GroupScaleReset>
43
43
  );
44
44
  }
@@ -5,7 +5,7 @@ import * as PopoverPrimitive from '@radix-ui/react-popover';
5
5
  import classNames from 'clsx';
6
6
  import { Ref } from 'react';
7
7
  import { withClassName } from '../../hooks/withClassName.js';
8
- import { BoxContext } from '../box/Box.js';
8
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
9
9
 
10
10
  const StyledContent = withClassName(
11
11
  PopoverPrimitive.Content,
@@ -55,7 +55,7 @@ export const PopoverContent = function PopoverContent({
55
55
  }) {
56
56
  return (
57
57
  <PopoverPrimitive.Portal forceMount={forceMount}>
58
- <BoxContext.Provider value={{ spacingScale: 1 }}>
58
+ <GroupScaleReset>
59
59
  <StyledContent
60
60
  {...props}
61
61
  forceMount={forceMount}
@@ -73,7 +73,7 @@ export const PopoverContent = function PopoverContent({
73
73
  >
74
74
  {children}
75
75
  </StyledContent>
76
- </BoxContext.Provider>
76
+ </GroupScaleReset>
77
77
  </PopoverPrimitive.Portal>
78
78
  );
79
79
  };
@@ -12,7 +12,7 @@ import {
12
12
  useContext,
13
13
  } from 'react';
14
14
  import { withClassName } from '../../hooks/withClassName.js';
15
- import { BoxContext } from '../box/Box.js';
15
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
16
16
  import { Button, ButtonProps } from '../button/Button.js';
17
17
  import { getButtonClassName } from '../button/classes.js';
18
18
  import { Icon } from '../icon/index.js';
@@ -146,7 +146,7 @@ export const SelectContent = withPassthroughNativeRender(
146
146
  ({ ref: forwardedRef, children, inDialog, className, ...props }) => {
147
147
  return (
148
148
  <SelectPrimitive.Portal>
149
- <BoxContext.Provider value={{ spacingScale: 1 }}>
149
+ <GroupScaleReset>
150
150
  <SelectPrimitive.Content
151
151
  className={classNames(
152
152
  'layer-components:(overflow-hidden bg-white rounded-md border border-solid border border-black z-menu shadow-lg)',
@@ -171,7 +171,7 @@ export const SelectContent = withPassthroughNativeRender(
171
171
  <Icon name="chevron" />
172
172
  </SelectPrimitive.ScrollDownButton>
173
173
  </SelectPrimitive.Content>
174
- </BoxContext.Provider>
174
+ </GroupScaleReset>
175
175
  </SelectPrimitive.Portal>
176
176
  );
177
177
  },
@@ -1,8 +1,6 @@
1
- 'use client';
2
-
3
1
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
4
2
  import classNames from 'clsx';
5
- import { BoxContext } from '../box/Box.js';
3
+ import { GroupScaleReset } from '../../systems/GroupScale.js';
6
4
 
7
5
  export interface TooltipContentProps
8
6
  extends TooltipPrimitive.TooltipContentProps {
@@ -17,7 +15,7 @@ function Content({
17
15
  }: TooltipPrimitive.TooltipContentProps) {
18
16
  return (
19
17
  <TooltipPrimitive.Portal>
20
- <BoxContext.Provider value={{ spacingScale: 1 }}>
18
+ <GroupScaleReset>
21
19
  <TooltipPrimitive.Content
22
20
  className={classNames(
23
21
  'layer-components:(relative rounded-sm py-2 px-3 text-sm leading-tight shadow-sm select-none hidden z-tooltip)',
@@ -39,7 +37,7 @@ function Content({
39
37
  {children}
40
38
  <TooltipPrimitive.Arrow className="layer-components:arrow" />
41
39
  </TooltipPrimitive.Content>
42
- </BoxContext.Provider>
40
+ </GroupScaleReset>
43
41
  </TooltipPrimitive.Portal>
44
42
  );
45
43
  }
@@ -0,0 +1,35 @@
1
+ import { createContext, CSSProperties, ReactNode, useContext } from 'react';
2
+
3
+ export const GroupScaleContext = createContext<number>(1);
4
+
5
+ const GROUP_SCALE_NESTING_FACTOR = 0.75;
6
+
7
+ export const GroupScaleLayer = ({ children }: { children?: ReactNode }) => {
8
+ const current = useGroupScale();
9
+ return (
10
+ <GroupScaleContext.Provider value={current * GROUP_SCALE_NESTING_FACTOR}>
11
+ {children}
12
+ </GroupScaleContext.Provider>
13
+ );
14
+ };
15
+
16
+ export function useGroupScale() {
17
+ return useContext(GroupScaleContext);
18
+ }
19
+
20
+ export function useGroupScaleStyles(composeStyles?: CSSProperties) {
21
+ const scale = useGroupScale();
22
+ return {
23
+ '--spacing-scale': scale,
24
+ '--local-corner-scale': scale,
25
+ ...composeStyles,
26
+ };
27
+ }
28
+
29
+ export const GroupScaleReset = ({ children }: { children: ReactNode }) => {
30
+ return (
31
+ <GroupScaleContext.Provider value={1}>
32
+ {children}
33
+ </GroupScaleContext.Provider>
34
+ );
35
+ };