@cocso-ui/react 1.11.0 → 1.12.0

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 (92) hide show
  1. package/dist/cjs/components/breadcrumb/breadcrumb.d.ts +24 -3
  2. package/dist/cjs/components/breadcrumb/breadcrumb.js +44 -2
  3. package/dist/cjs/components/breadcrumb/breadcrumb.module.css.js +2 -2
  4. package/dist/cjs/components/card/card.d.ts +49 -2
  5. package/dist/cjs/components/card/card.js +76 -10
  6. package/dist/cjs/components/card/card.module.css.js +2 -2
  7. package/dist/cjs/components/copy-button/copy-button.d.ts +29 -0
  8. package/dist/cjs/components/copy-button/copy-button.js +67 -0
  9. package/dist/cjs/components/empty-state/empty-state.d.ts +30 -0
  10. package/dist/cjs/components/empty-state/empty-state.js +50 -0
  11. package/dist/cjs/components/empty-state/empty-state.module.css.js +9 -0
  12. package/dist/cjs/components/file-uploader/file-uploader.d.ts +80 -0
  13. package/dist/cjs/components/file-uploader/file-uploader.js +258 -0
  14. package/dist/cjs/components/file-uploader/file-uploader.module.css.js +9 -0
  15. package/dist/cjs/components/form-field/form-field-context.d.ts +31 -0
  16. package/dist/cjs/components/form-field/form-field-context.js +53 -0
  17. package/dist/cjs/components/form-field/form-field-parts.d.ts +52 -0
  18. package/dist/cjs/components/form-field/form-field-parts.js +109 -0
  19. package/dist/cjs/components/form-field/form-field.d.ts +44 -0
  20. package/dist/cjs/components/form-field/form-field.js +61 -0
  21. package/dist/cjs/components/form-field/form-field.module.css.js +9 -0
  22. package/dist/cjs/components/info-popover/info-popover.d.ts +43 -0
  23. package/dist/cjs/components/info-popover/info-popover.js +57 -0
  24. package/dist/cjs/components/info-popover/info-popover.module.css.js +9 -0
  25. package/dist/cjs/components/loading-overlay/loading-overlay.d.ts +33 -0
  26. package/dist/cjs/components/loading-overlay/loading-overlay.js +68 -0
  27. package/dist/cjs/components/loading-overlay/loading-overlay.module.css.js +9 -0
  28. package/dist/cjs/components/number-input/number-input.d.ts +39 -0
  29. package/dist/cjs/components/number-input/number-input.js +167 -0
  30. package/dist/cjs/components/section-header/section-header.d.ts +48 -0
  31. package/dist/cjs/components/section-header/section-header.js +210 -0
  32. package/dist/cjs/components/section-header/section-header.module.css.js +9 -0
  33. package/dist/cjs/components/segmented-control/segmented-control.d.ts +55 -0
  34. package/dist/cjs/components/segmented-control/segmented-control.js +119 -0
  35. package/dist/cjs/components/segmented-control/segmented-control.module.css.js +9 -0
  36. package/dist/cjs/components/selection-chip/selection-chip.d.ts +22 -0
  37. package/dist/cjs/components/selection-chip/selection-chip.js +32 -0
  38. package/dist/cjs/components/selection-chip/selection-chip.module.css.js +9 -0
  39. package/dist/cjs/components/skeleton/skeleton.d.ts +7 -1
  40. package/dist/cjs/components/skeleton/skeleton.js +20 -2
  41. package/dist/cjs/components/summary-card/summary-card.d.ts +47 -0
  42. package/dist/cjs/components/summary-card/summary-card.js +89 -0
  43. package/dist/cjs/components/summary-card/summary-card.module.css.js +9 -0
  44. package/dist/cjs/index.d.ts +15 -2
  45. package/dist/cjs/index.js +24 -0
  46. package/dist/esm/components/breadcrumb/breadcrumb.d.mts +24 -3
  47. package/dist/esm/components/breadcrumb/breadcrumb.mjs +44 -2
  48. package/dist/esm/components/breadcrumb/breadcrumb.module.css.mjs +1 -1
  49. package/dist/esm/components/card/card.d.mts +49 -2
  50. package/dist/esm/components/card/card.mjs +76 -10
  51. package/dist/esm/components/card/card.module.css.mjs +1 -1
  52. package/dist/esm/components/copy-button/copy-button.d.mts +29 -0
  53. package/dist/esm/components/copy-button/copy-button.mjs +65 -0
  54. package/dist/esm/components/empty-state/empty-state.d.mts +30 -0
  55. package/dist/esm/components/empty-state/empty-state.mjs +48 -0
  56. package/dist/esm/components/empty-state/empty-state.module.css.mjs +3 -0
  57. package/dist/esm/components/file-uploader/file-uploader.d.mts +80 -0
  58. package/dist/esm/components/file-uploader/file-uploader.mjs +256 -0
  59. package/dist/esm/components/file-uploader/file-uploader.module.css.mjs +3 -0
  60. package/dist/esm/components/form-field/form-field-context.d.mts +31 -0
  61. package/dist/esm/components/form-field/form-field-context.mjs +49 -0
  62. package/dist/esm/components/form-field/form-field-parts.d.mts +52 -0
  63. package/dist/esm/components/form-field/form-field-parts.mjs +105 -0
  64. package/dist/esm/components/form-field/form-field.d.mts +44 -0
  65. package/dist/esm/components/form-field/form-field.mjs +59 -0
  66. package/dist/esm/components/form-field/form-field.module.css.mjs +3 -0
  67. package/dist/esm/components/info-popover/info-popover.d.mts +43 -0
  68. package/dist/esm/components/info-popover/info-popover.mjs +55 -0
  69. package/dist/esm/components/info-popover/info-popover.module.css.mjs +3 -0
  70. package/dist/esm/components/loading-overlay/loading-overlay.d.mts +33 -0
  71. package/dist/esm/components/loading-overlay/loading-overlay.mjs +66 -0
  72. package/dist/esm/components/loading-overlay/loading-overlay.module.css.mjs +3 -0
  73. package/dist/esm/components/number-input/number-input.d.mts +39 -0
  74. package/dist/esm/components/number-input/number-input.mjs +165 -0
  75. package/dist/esm/components/section-header/section-header.d.mts +48 -0
  76. package/dist/esm/components/section-header/section-header.mjs +208 -0
  77. package/dist/esm/components/section-header/section-header.module.css.mjs +3 -0
  78. package/dist/esm/components/segmented-control/segmented-control.d.mts +55 -0
  79. package/dist/esm/components/segmented-control/segmented-control.mjs +117 -0
  80. package/dist/esm/components/segmented-control/segmented-control.module.css.mjs +3 -0
  81. package/dist/esm/components/selection-chip/selection-chip.d.mts +22 -0
  82. package/dist/esm/components/selection-chip/selection-chip.mjs +30 -0
  83. package/dist/esm/components/selection-chip/selection-chip.module.css.mjs +3 -0
  84. package/dist/esm/components/skeleton/skeleton.d.mts +7 -1
  85. package/dist/esm/components/skeleton/skeleton.mjs +20 -2
  86. package/dist/esm/components/summary-card/summary-card.d.mts +47 -0
  87. package/dist/esm/components/summary-card/summary-card.mjs +87 -0
  88. package/dist/esm/components/summary-card/summary-card.module.css.mjs +3 -0
  89. package/dist/esm/index.css +2 -2
  90. package/dist/esm/index.d.mts +15 -2
  91. package/dist/esm/index.mjs +12 -0
  92. package/package.json +1 -1
@@ -0,0 +1,117 @@
1
+ "use client";
2
+ import { useId, useRef, useState, useLayoutEffect } from 'react';
3
+ import { cn } from '../../cn.mjs';
4
+ import styles from './segmented-control.module.css.mjs';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+ import { RadioGroup } from '@base-ui/react/radio-group';
7
+ import { Radio } from '@base-ui/react/radio';
8
+
9
+ /**
10
+ * A single choice among two or three options, drawn as one pill-shaped track.
11
+ *
12
+ * Built on Base UI's radio group, so it is a `radiogroup` of `radio`s: Tab
13
+ * reaches the selected segment and the arrow keys move the selection, the way
14
+ * a set of radio buttons behaves.
15
+ */
16
+ function SegmentedControl({
17
+ value,
18
+ options,
19
+ onChange,
20
+ description,
21
+ className,
22
+ disabled = false,
23
+ fitContent = false,
24
+ size = "medium",
25
+ "aria-label": ariaLabel,
26
+ "aria-labelledby": ariaLabelledBy
27
+ }) {
28
+ const descriptionId = useId();
29
+ const trackRef = useRef(null);
30
+ const [measured, setMeasured] = useState(null);
31
+ const selectedIndex = options.findIndex(option => option.value === value);
32
+ const hasDescription = options.some(option => option.description);
33
+
34
+ // Only the content-width mode measures: an even split is pure CSS.
35
+ useLayoutEffect(() => {
36
+ if (!fitContent) {
37
+ return;
38
+ }
39
+ const track = trackRef.current;
40
+ if (!track) {
41
+ return;
42
+ }
43
+ const measure = () => {
44
+ const segment = track.querySelectorAll('[role="radio"]')[Math.max(selectedIndex, 0)];
45
+ if (!segment) {
46
+ return;
47
+ }
48
+ // `offsetLeft` is physical; the indicator is placed on the inline axis
49
+ // so it lands on the right segment when the direction flips.
50
+ const rtl = getComputedStyle(track).direction === "rtl";
51
+ const start = rtl ? track.clientWidth - segment.offsetLeft - segment.offsetWidth : segment.offsetLeft;
52
+ setMeasured({
53
+ start,
54
+ size: segment.offsetWidth
55
+ });
56
+ };
57
+ measure();
58
+ // Label widths change when a web font loads or the container resizes.
59
+ const observer = new ResizeObserver(measure);
60
+ observer.observe(track);
61
+ return () => observer.disconnect();
62
+ }, [fitContent, selectedIndex]);
63
+
64
+ // In content-width mode the indicator is not rendered until it has been
65
+ // measured: a first style has nothing to transition from, so it appears in
66
+ // place instead of growing in from the track's edge on every mount.
67
+ const showIndicator = !fitContent || measured !== null;
68
+ const indicatorStyle = fitContent ? measured && {
69
+ "--segmented-control-indicator-start": `${measured.start}px`,
70
+ "--segmented-control-indicator-size": `${measured.size}px`
71
+ } : {
72
+ "--segmented-control-count": options.length,
73
+ "--segmented-control-index": Math.max(selectedIndex, 0)
74
+ };
75
+ const control = /*#__PURE__*/jsxs(RadioGroup, {
76
+ "aria-describedby": description ? descriptionId : undefined,
77
+ "aria-label": ariaLabel,
78
+ "aria-labelledby": ariaLabelledBy,
79
+ className: cn(styles.track, styles[size], fitContent ? styles.fit : styles.even, hasDescription && styles.twoLine, !description && className),
80
+ "data-cocso-component": "segmented-control",
81
+ disabled: disabled,
82
+ onValueChange: next => onChange(next),
83
+ ref: trackRef,
84
+ value: value,
85
+ children: [showIndicator && /*#__PURE__*/jsx("span", {
86
+ "aria-hidden": true,
87
+ className: cn(styles.indicator, selectedIndex < 0 && styles.indicatorHidden),
88
+ "data-cocso-component": "segmented-control-indicator",
89
+ style: indicatorStyle
90
+ }), options.map(option => /*#__PURE__*/jsxs(Radio.Root, {
91
+ className: styles.segment,
92
+ "data-cocso-component": "segmented-control-item",
93
+ value: option.value,
94
+ children: [/*#__PURE__*/jsx("span", {
95
+ className: styles.label,
96
+ children: option.label
97
+ }), option.description && /*#__PURE__*/jsx("span", {
98
+ className: styles.optionDescription,
99
+ children: option.description
100
+ })]
101
+ }, option.value))]
102
+ });
103
+ if (!description) {
104
+ return control;
105
+ }
106
+ return /*#__PURE__*/jsxs("div", {
107
+ className: cn(styles.root, fitContent && styles.rootFit, className),
108
+ "data-cocso-component": "segmented-control-root",
109
+ children: [control, /*#__PURE__*/jsx("span", {
110
+ className: styles.description,
111
+ id: descriptionId,
112
+ children: description
113
+ })]
114
+ });
115
+ }
116
+
117
+ export { SegmentedControl };
@@ -0,0 +1,3 @@
1
+ var styles = {"root":"segmented-control-module_root__Eg5Cg","rootFit":"segmented-control-module_rootFit__HH5g9","track":"segmented-control-module_track__tEmZy","fit":"segmented-control-module_fit__E4VDX","medium":"segmented-control-module_medium__ZQMNB","small":"segmented-control-module_small__nqpQ3","indicator":"segmented-control-module_indicator__VORjV","even":"segmented-control-module_even__aAaDd","indicatorHidden":"segmented-control-module_indicatorHidden__uYrjU","segment":"segmented-control-module_segment__3-9eW","twoLine":"segmented-control-module_twoLine__6RCfj","label":"segmented-control-module_label__3RVi9","optionDescription":"segmented-control-module_optionDescription__iZfff","description":"segmented-control-module_description__WMQQf"};
2
+
3
+ export { styles as default };
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ComponentProps } from 'react';
3
+
4
+ interface SelectionChipProps extends Omit<ComponentProps<"button">, "type"> {
5
+ /**
6
+ * Whether everything this chip stands for is currently selected. Drawn in
7
+ * the primary tint and exposed as `aria-pressed`, so the state is not
8
+ * carried by colour alone.
9
+ */
10
+ active?: boolean;
11
+ }
12
+ /**
13
+ * A bulk-selection chip, placed above a multi-select list.
14
+ *
15
+ * "Select all", "select every tagged item", a group name — a button that adds
16
+ * or removes several items at once. `active` shows that every item it targets
17
+ * is already selected, so pressing it again clears them.
18
+ */
19
+ declare function SelectionChip({ ref, className, active, ...props }: SelectionChipProps): react_jsx_runtime.JSX.Element;
20
+
21
+ export { SelectionChip };
22
+ export type { SelectionChipProps };
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { cn } from '../../cn.mjs';
3
+ import styles from './selection-chip.module.css.mjs';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ /**
7
+ * A bulk-selection chip, placed above a multi-select list.
8
+ *
9
+ * "Select all", "select every tagged item", a group name — a button that adds
10
+ * or removes several items at once. `active` shows that every item it targets
11
+ * is already selected, so pressing it again clears them.
12
+ */
13
+ function SelectionChip({
14
+ ref,
15
+ className,
16
+ active = false,
17
+ ...props
18
+ }) {
19
+ return /*#__PURE__*/jsx("button", {
20
+ "aria-pressed": active,
21
+ className: cn(styles.chip, active && styles.active, className),
22
+ "data-active": active || undefined,
23
+ "data-cocso-component": "selection-chip",
24
+ ref: ref,
25
+ type: "button",
26
+ ...props
27
+ });
28
+ }
29
+
30
+ export { SelectionChip };
@@ -0,0 +1,3 @@
1
+ var styles = {"chip":"selection-chip-module_chip__QS6TC","active":"selection-chip-module_active__nuRn2"};
2
+
3
+ export { styles as default };
@@ -6,10 +6,16 @@ type SkeletonVariant = "text" | "circular" | "rectangular";
6
6
  type SkeletonAnimation = "pulse" | "wave" | "none";
7
7
  interface SkeletonProps extends ComponentProps<"div"> {
8
8
  animation?: SkeletonAnimation;
9
+ /** Shorthand for `variant="circular"` — an avatar or icon placeholder. */
10
+ circle?: boolean;
11
+ /** Block size. A number is read as pixels; a string is used as-is. */
12
+ height?: number | string;
9
13
  variant?: SkeletonVariant;
14
+ /** Inline size. A number is read as pixels; a string is used as-is. */
15
+ width?: number | string;
10
16
  }
11
17
  /** Loading placeholder with configurable shape and animation. */
12
- declare function Skeleton({ ref, className, style, variant, animation, ...props }: SkeletonProps): react_jsx_runtime.JSX.Element;
18
+ declare function Skeleton({ ref, className, style: _style, variant, animation, circle, width, height, ...props }: SkeletonProps): react_jsx_runtime.JSX.Element;
13
19
 
14
20
  export { Skeleton };
15
21
  export type { SkeletonAnimation, SkeletonProps, SkeletonVariant };
@@ -3,19 +3,37 @@ import { cn } from '../../cn.mjs';
3
3
  import styles from './skeleton.module.css.mjs';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
+ const toLength = value => typeof value === "number" ? `${value}px` : value;
7
+
6
8
  /** Loading placeholder with configurable shape and animation. */
7
9
  function Skeleton({
8
10
  ref,
9
11
  className,
10
- style,
12
+ style: _style,
11
13
  variant = "text",
12
14
  animation = "pulse",
15
+ circle = false,
16
+ width,
17
+ height,
13
18
  ...props
14
19
  }) {
20
+ const resolvedVariant = circle ? "circular" : variant;
21
+
22
+ // The size feeds the custom properties the module already reads, so a
23
+ // consumer's own `style.width` / `style.height` still wins over these.
24
+ const style = {
25
+ ...(width === undefined ? {} : {
26
+ "--cocso-skeleton-width": toLength(width)
27
+ }),
28
+ ...(height === undefined ? {} : {
29
+ "--cocso-skeleton-height": toLength(height)
30
+ }),
31
+ ..._style
32
+ };
15
33
  return /*#__PURE__*/jsx("div", {
16
34
  "aria-hidden": "true",
17
35
  className: cn(skeleton({
18
- variant,
36
+ variant: resolvedVariant,
19
37
  animation
20
38
  }), styles.skeleton, animation === "pulse" && styles.pulse, animation === "wave" && styles.wave, className),
21
39
  ref: ref,
@@ -0,0 +1,47 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import { RenderProp } from '../../primitives/use-render.mjs';
4
+
5
+ interface SummaryCardProps extends ComponentProps<"div"> {
6
+ /** Leading icon. Decorative — the label carries the meaning. */
7
+ icon?: ReactNode;
8
+ /** What the figure counts, in a few words. */
9
+ label: ReactNode;
10
+ }
11
+ declare function SummaryCardRoot({ className, icon, label, children, ...props }: SummaryCardProps): react_jsx_runtime.JSX.Element;
12
+ interface SummaryCardValueProps extends Omit<ComponentProps<"a">, "children"> {
13
+ /** The figure. */
14
+ count: number | string;
15
+ /**
16
+ * Where the figure leads — the list it counts. Without one (and without
17
+ * `render`) the figure is plain text.
18
+ */
19
+ href?: string;
20
+ /**
21
+ * Element the linked figure renders as — the router's link, for example
22
+ * `render={(props) => <NextLink {...props} href={props.href ?? ""} />}`.
23
+ * It receives `href`, `className` and `children`. Defaults to `<a>`.
24
+ */
25
+ render?: RenderProp;
26
+ /** Unit after the figure, e.g. `"건"` or `"%"`. */
27
+ suffix?: ReactNode;
28
+ }
29
+ declare function SummaryCardValue({ className, count, href, render, suffix, ...props }: SummaryCardValueProps): react_jsx_runtime.JSX.Element;
30
+ /**
31
+ * One headline figure on a dashboard: what it counts, the figure, and —
32
+ * usually — a link through to the list behind it.
33
+ *
34
+ * The root paints no surface. Put it in a `Card` where it should read as a
35
+ * card; a grid of four on a plain page does not need one.
36
+ *
37
+ * @example
38
+ * <SummaryCard icon={<PersonIcon />} label="New users">
39
+ * <SummaryCard.Value count={42} href="/users" />
40
+ * </SummaryCard>
41
+ */
42
+ declare const SummaryCard: typeof SummaryCardRoot & {
43
+ Value: typeof SummaryCardValue;
44
+ };
45
+
46
+ export { SummaryCard };
47
+ export type { SummaryCardProps, SummaryCardValueProps };
@@ -0,0 +1,87 @@
1
+ import { ArrowIOSForwardIcon } from '@cocso-ui/react-icons';
2
+ import { cn } from '../../cn.mjs';
3
+ import styles from './summary-card.module.css.mjs';
4
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
+ import { Typography } from '../typography/typography.mjs';
6
+ import { useRender } from '@base-ui/react/use-render';
7
+ import { mergeProps } from '@base-ui/react/merge-props';
8
+
9
+ function SummaryCardRoot({
10
+ className,
11
+ icon,
12
+ label,
13
+ children,
14
+ ...props
15
+ }) {
16
+ return /*#__PURE__*/jsxs("div", {
17
+ className: cn(styles.root, className),
18
+ "data-cocso-component": "summary-card",
19
+ ...props,
20
+ children: [/*#__PURE__*/jsxs("div", {
21
+ className: styles.header,
22
+ children: [icon && /*#__PURE__*/jsx("span", {
23
+ "aria-hidden": "true",
24
+ className: styles.icon,
25
+ children: icon
26
+ }), /*#__PURE__*/jsx("span", {
27
+ className: styles.label,
28
+ children: label
29
+ })]
30
+ }), children]
31
+ });
32
+ }
33
+ const VALUE_HOOK = {
34
+ "data-cocso-component": "summary-card-value"
35
+ };
36
+ function SummaryCardValue({
37
+ className,
38
+ count,
39
+ href,
40
+ render,
41
+ suffix,
42
+ ...props
43
+ }) {
44
+ const linked = href !== undefined || render !== undefined;
45
+ const element = useRender({
46
+ render,
47
+ props: mergeProps({
48
+ ...VALUE_HOOK,
49
+ className: cn(styles.value, linked && styles.link, className),
50
+ href,
51
+ children: /*#__PURE__*/jsxs(Fragment, {
52
+ children: [count, suffix, linked && /*#__PURE__*/jsx(ArrowIOSForwardIcon, {
53
+ "aria-hidden": "true",
54
+ className: styles.chevron,
55
+ size: 16
56
+ })]
57
+ })
58
+ }, props),
59
+ defaultTagName: linked ? "a" : "span"
60
+ });
61
+ // Typography sets the figure's size and weight, so it follows the type
62
+ // scale (including its responsive steps) rather than a copied number.
63
+ return /*#__PURE__*/jsx(Typography, {
64
+ render: element,
65
+ size: "large",
66
+ type: "body",
67
+ weight: "bold"
68
+ });
69
+ }
70
+
71
+ /**
72
+ * One headline figure on a dashboard: what it counts, the figure, and —
73
+ * usually — a link through to the list behind it.
74
+ *
75
+ * The root paints no surface. Put it in a `Card` where it should read as a
76
+ * card; a grid of four on a plain page does not need one.
77
+ *
78
+ * @example
79
+ * <SummaryCard icon={<PersonIcon />} label="New users">
80
+ * <SummaryCard.Value count={42} href="/users" />
81
+ * </SummaryCard>
82
+ */
83
+ const SummaryCard = Object.assign(SummaryCardRoot, {
84
+ Value: SummaryCardValue
85
+ });
86
+
87
+ export { SummaryCard };
@@ -0,0 +1,3 @@
1
+ var styles = {"root":"summary-card-module_root__6-n2Z","header":"summary-card-module_header__eRIMm","icon":"summary-card-module_icon__pmw-V","label":"summary-card-module_label__CBgob","value":"summary-card-module_value__uu08J","link":"summary-card-module_link__jyia5","chevron":"summary-card-module_chevron__uejaT"};
2
+
3
+ export { styles as default };