@sanity-labs/ui-poc 0.0.1-alpha.11 → 0.0.1-alpha.12

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 (33) hide show
  1. package/dist/index.d.ts +71 -17
  2. package/dist/index.js +202 -23
  3. package/dist/index.js.map +1 -1
  4. package/dist/styles.css +1 -1
  5. package/package.json +2 -1
  6. package/src/components/box/Box.tsx +3 -3
  7. package/src/components/card/Card.tsx +3 -3
  8. package/src/components/checkbox/Checkbox.tsx +51 -0
  9. package/src/components/checkbox/checkbox.css +36 -0
  10. package/src/components/checkbox/checkbox.props.ts +20 -0
  11. package/src/components/container/Container.tsx +3 -3
  12. package/src/components/flex/Flex.tsx +3 -3
  13. package/src/components/grid/Grid.tsx +3 -3
  14. package/src/components/heading/Heading.tsx +3 -3
  15. package/src/components/icon/icon.props.ts +3 -3
  16. package/src/components/index.css +5 -0
  17. package/src/components/label/Label.tsx +27 -0
  18. package/src/components/label/label.css +3 -0
  19. package/src/components/label/label.props.ts +15 -0
  20. package/src/components/radio/Radio.tsx +34 -0
  21. package/src/components/radio/radio.css +26 -0
  22. package/src/components/radio/radio.props.ts +15 -0
  23. package/src/components/switch/Switch.tsx +50 -0
  24. package/src/components/switch/switch.css +40 -0
  25. package/src/components/switch/switch.props.ts +20 -0
  26. package/src/components/text/Text.tsx +3 -3
  27. package/src/components/visually-hidden/VisuallyHidden.tsx +24 -0
  28. package/src/components/visually-hidden/visually-hidden.css +9 -0
  29. package/src/components/visually-hidden/visuallyHidden.props.ts +13 -0
  30. package/src/css/classes/system/radius.css +1 -1
  31. package/src/css/global/reset.css +2 -3
  32. package/src/css/tokens/border.css +1 -1
  33. package/src/index.ts +5 -0
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import type {ComponentProps} from 'react'
2
+ import type {ComponentPropsWithRef} from 'react'
3
+ import type {ElementType} from 'react'
1
4
  import {JSX} from 'react/jsx-runtime'
2
- import {default as React_2} from 'react'
5
+ import type {SVGProps} from 'react'
3
6
 
4
7
  declare const ALIGN_ITEMS: readonly ['baseline', 'center', 'flex-end', 'flex-start', 'stretch']
5
8
 
@@ -21,10 +24,10 @@ declare type BorderProps = {
21
24
  }
22
25
 
23
26
  /** @public */
24
- export declare function Box<T extends React_2.ElementType = 'div'>({
27
+ export declare function Box<T extends ElementType = 'div'>({
25
28
  display,
26
29
  ...props
27
- }: BoxProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof BoxProps<T>>): JSX.Element
30
+ }: BoxProps<T> & Omit<ComponentPropsWithRef<T>, keyof BoxProps<T>>): JSX.Element
28
31
 
29
32
  /** @public */
30
33
  declare interface BoxProps<T extends React.ElementType> extends LayoutProps {
@@ -35,11 +38,11 @@ declare interface BoxProps<T extends React.ElementType> extends LayoutProps {
35
38
  }
36
39
 
37
40
  /** @public */
38
- export declare function Card<T extends React_2.ElementType = 'div'>({
41
+ export declare function Card<T extends ElementType = 'div'>({
39
42
  density,
40
43
  tone,
41
44
  ...props
42
- }: CardProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof CardProps<T>>): JSX.Element
45
+ }: CardProps<T> & Omit<ComponentPropsWithRef<T>, keyof CardProps<T>>): JSX.Element
43
46
 
44
47
  /** @public */
45
48
  declare interface CardProps<T extends React.ElementType> extends MarginProps, ToneProps {
@@ -49,6 +52,17 @@ declare interface CardProps<T extends React.ElementType> extends MarginProps, To
49
52
  density?: Responsive<Density>
50
53
  }
51
54
 
55
+ /** @beta */
56
+ export declare function Checkbox(props: CheckboxProps): JSX.Element
57
+
58
+ /** @beta */
59
+ declare interface CheckboxProps extends React.ComponentProps<'input'>, MarginProps {
60
+ /** Input label */
61
+ label: React.ReactNode
62
+ /** Indeterminate state */
63
+ indeterminate?: boolean
64
+ }
65
+
52
66
  /** @public */
53
67
  export declare function Code<T extends React.ElementType = 'pre'>({
54
68
  size,
@@ -75,10 +89,10 @@ declare type CodeSize = (typeof CODE_SIZE)[number]
75
89
  declare type CodeTag = (typeof CODE_TAG)[number]
76
90
 
77
91
  /** @public */
78
- export declare function Container<T extends React_2.ElementType = 'div'>({
92
+ export declare function Container<T extends ElementType = 'div'>({
79
93
  marginX,
80
94
  ...props
81
- }: ContainerProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof ContainerProps<T>>): JSX.Element
95
+ }: ContainerProps<T> & Omit<ComponentPropsWithRef<T>, keyof ContainerProps<T>>): JSX.Element
82
96
 
83
97
  declare const CONTAINER_SIZE: readonly [0, 1, 2, 3, 4, 5]
84
98
 
@@ -115,10 +129,10 @@ export declare function Divider(props: DividerProps): JSX.Element
115
129
  declare interface DividerProps extends React.ComponentProps<'hr'>, MarginProps {}
116
130
 
117
131
  /** @public */
118
- export declare function Flex<T extends React_2.ElementType = 'div'>({
132
+ export declare function Flex<T extends ElementType = 'div'>({
119
133
  display,
120
134
  ...props
121
- }: FlexProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof FlexProps<T>>): JSX.Element
135
+ }: FlexProps<T> & Omit<ComponentPropsWithRef<T>, keyof FlexProps<T>>): JSX.Element
122
136
 
123
137
  declare const FLEX_DIRECTION: readonly ['row', 'row-reverse', 'column', 'column-reverse']
124
138
 
@@ -171,10 +185,10 @@ declare type GapProps = {
171
185
  }
172
186
 
173
187
  /** @public */
174
- export declare function Grid<T extends React_2.ElementType = 'div'>({
188
+ export declare function Grid<T extends ElementType = 'div'>({
175
189
  display,
176
190
  ...props
177
- }: GridProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof GridProps<T>>): JSX.Element
191
+ }: GridProps<T> & Omit<ComponentPropsWithRef<T>, keyof GridProps<T>>): JSX.Element
178
192
 
179
193
  declare const GRID_AUTO_FLOW: readonly ['row', 'column', 'row dense', 'column dense', 'dense']
180
194
 
@@ -218,11 +232,11 @@ declare interface GridProps<T extends React.ElementType>
218
232
  }
219
233
 
220
234
  /** @public */
221
- export declare function Heading<T extends React_2.ElementType = 'h2'>({
235
+ export declare function Heading<T extends ElementType = 'h2'>({
222
236
  size,
223
237
  weight,
224
238
  ...props
225
- }: HeadingProps & Omit<React_2.ComponentPropsWithRef<T>, keyof HeadingProps>): JSX.Element
239
+ }: HeadingProps & Omit<ComponentPropsWithRef<T>, keyof HeadingProps>): JSX.Element
226
240
 
227
241
  declare const HEADING_SIZE: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
228
242
 
@@ -255,9 +269,9 @@ export declare function Icon({icon: Component, size, ...props}: IconProps): JSX.
255
269
  declare const ICON_SIZE: readonly [0, 1, 2, 3, 4]
256
270
 
257
271
  /** @public */
258
- declare interface IconProps extends React_2.ComponentProps<'svg'>, MarginProps, ToneProps {
272
+ declare interface IconProps extends ComponentProps<'svg'>, MarginProps, ToneProps {
259
273
  /** Icon to render */
260
- icon: React_2.ComponentType<React_2.SVGProps<SVGSVGElement>>
274
+ icon: React.ComponentType<SVGProps<SVGSVGElement>>
261
275
  /** CSS **font-size** property */
262
276
  size?: Responsive<IconSize>
263
277
  /** CSS **color** property */
@@ -277,6 +291,15 @@ declare const JUSTIFY_CONTENT: readonly [
277
291
 
278
292
  declare type JustifyContent = (typeof JUSTIFY_CONTENT)[number]
279
293
 
294
+ /** @beta */
295
+ export declare function Label(props: LabelProps): JSX.Element
296
+
297
+ /** @beta */
298
+ declare interface LabelProps extends React.ComponentProps<'label'>, MarginProps {
299
+ /** Element to render */
300
+ disabled?: boolean
301
+ }
302
+
280
303
  declare interface LayoutProps
281
304
  extends
282
305
  ToneProps,
@@ -358,6 +381,15 @@ declare type PositionProps = {
358
381
  left?: Responsive<SpaceAuto>
359
382
  }
360
383
 
384
+ /** @beta */
385
+ export declare function Radio(props: RadioProps): JSX.Element
386
+
387
+ /** @beta */
388
+ declare interface RadioProps extends React.ComponentProps<'input'>, MarginProps {
389
+ /** Input label */
390
+ label: React.ReactNode
391
+ }
392
+
361
393
  declare const RADIUS: readonly [0, 1, 2, 3, 4, 5, 6, 'full']
362
394
 
363
395
  declare type Radius = (typeof RADIUS)[number]
@@ -397,11 +429,22 @@ declare const SPACE_AUTO: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'auto']
397
429
 
398
430
  declare type SpaceAuto = (typeof SPACE_AUTO)[number]
399
431
 
432
+ /** @beta */
433
+ export declare function Switch(props: SwitchProps): JSX.Element
434
+
435
+ /** @beta */
436
+ declare interface SwitchProps extends React.ComponentProps<'input'>, MarginProps {
437
+ /** Input label */
438
+ label: React.ReactNode
439
+ /** Indeterminate state */
440
+ indeterminate?: boolean
441
+ }
442
+
400
443
  /** @public */
401
- declare function Text_2<T extends React_2.ElementType = 'span'>({
444
+ declare function Text_2<T extends ElementType = 'span'>({
402
445
  size,
403
446
  ...props
404
- }: TextProps<T> & Omit<React_2.ComponentPropsWithRef<T>, keyof TextProps<T>>): JSX.Element
447
+ }: TextProps<T> & Omit<ComponentPropsWithRef<T>, keyof TextProps<T>>): JSX.Element
405
448
  export {Text_2 as Text}
406
449
 
407
450
  declare const TEXT_ALIGN: readonly ['left', 'center', 'right', 'justify']
@@ -450,6 +493,17 @@ declare interface TypographyProps extends MarginProps, ToneProps {
450
493
  weight?: FontWeight
451
494
  }
452
495
 
496
+ /** @public */
497
+ export declare function VisuallyHidden<T extends ElementType = 'span'>(
498
+ props: VisuallyHiddenProps<T> & Omit<ComponentPropsWithRef<T>, keyof VisuallyHiddenProps<T>>,
499
+ ): JSX.Element
500
+
501
+ /** @public */
502
+ declare interface VisuallyHiddenProps<T extends React.ElementType> {
503
+ /** Element to render */
504
+ as?: T
505
+ }
506
+
453
507
  declare type WidthProps = {
454
508
  /** CSS **width** property */
455
509
  width?: Responsive<string>
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import classNames from "classnames";
3
- import { lazy, Suspense } from "react";
3
+ import { RemoveIcon, CheckmarkIcon } from "@sanity/icons";
4
+ import { useRef, useEffect, lazy, Suspense } from "react";
4
5
  const PREFIX = "sui", BREAKPOINTS_LENGTH = 6;
5
6
  function getProps(componentProps, propDefs) {
6
7
  const { allComponentProps, allPropDefs } = flattenCompositeProps(componentProps, propDefs), restProps = {};
@@ -415,7 +416,125 @@ const FONT_WEIGHT = ["regular", "medium", "semibold", "bold"], TEXT_ALIGN = ["le
415
416
  },
416
417
  ...marginProps,
417
418
  ...toneProps
418
- }, CODE_TAG = ["pre", "span"], CODE_SIZE = [0, 1, 2, 3, 4], codeProps = {
419
+ }, TEXT_SIZE = [0, 1, 2, 3, 4], textProps = {
420
+ as: {
421
+ type: "string"
422
+ },
423
+ size: {
424
+ type: "union",
425
+ className: "text-body",
426
+ values: TEXT_SIZE
427
+ },
428
+ ...typographyProps
429
+ };
430
+ function Text({
431
+ size = 2,
432
+ ...props
433
+ }) {
434
+ const { as, children, className, style, ...rest } = getProps({ size, ...props }, textProps), Component = as || "span";
435
+ return props.lineClamp && props.trim ? /* @__PURE__ */ jsx(
436
+ Component,
437
+ {
438
+ className: classNames("sui-Text", className?.replace("sui-line-clamp", "")),
439
+ style,
440
+ "data-ui": "Text",
441
+ ...rest,
442
+ children: /* @__PURE__ */ jsx("span", { className: "sui-line-clamp", children })
443
+ }
444
+ ) : /* @__PURE__ */ jsx(Component, { className: classNames("sui-Text", className), style, "data-ui": "Text", ...rest, children });
445
+ }
446
+ const labelProps = {
447
+ disabled: {
448
+ type: "boolean"
449
+ },
450
+ ...marginProps
451
+ };
452
+ function Label(props) {
453
+ const { children, className, style, disabled, ...rest } = getProps(props, labelProps);
454
+ return /* @__PURE__ */ jsx(
455
+ Text,
456
+ {
457
+ as: "label",
458
+ size: 1,
459
+ muted: disabled,
460
+ className: classNames(
461
+ "sui-Label sui-display-flex sui-align-items-center sui-gap2",
462
+ className
463
+ ),
464
+ style,
465
+ "data-ui": "Label",
466
+ ...rest,
467
+ children
468
+ }
469
+ );
470
+ }
471
+ const visuallyHiddenProps = {
472
+ as: {
473
+ type: "string"
474
+ }
475
+ };
476
+ function VisuallyHidden(props) {
477
+ const { as, children, className, style, ...rest } = getProps(props, visuallyHiddenProps);
478
+ return /* @__PURE__ */ jsx(
479
+ as || "span",
480
+ {
481
+ className: classNames("sui-VisuallyHidden", className),
482
+ style,
483
+ "data-ui": "VisuallyHidden",
484
+ ...rest,
485
+ children
486
+ }
487
+ );
488
+ }
489
+ const checkboxProps = {
490
+ label: {
491
+ type: "string"
492
+ },
493
+ indeterminate: {
494
+ type: "boolean"
495
+ },
496
+ ...marginProps
497
+ };
498
+ function Checkbox(props) {
499
+ const inputRef = useRef(null), { className, style, label, indeterminate, ...rest } = getProps(props, checkboxProps);
500
+ return useEffect(() => {
501
+ inputRef.current && (inputRef.current.indeterminate = indeterminate);
502
+ }, [indeterminate]), /* @__PURE__ */ jsxs(
503
+ Label,
504
+ {
505
+ className: classNames("sui-Checkbox", className),
506
+ style,
507
+ "data-ui": "Checkbox",
508
+ disabled: props.disabled,
509
+ children: [
510
+ /* @__PURE__ */ jsx(
511
+ VisuallyHidden,
512
+ {
513
+ as: "input",
514
+ type: "checkbox",
515
+ className: "sui-CheckboxInput",
516
+ ref: inputRef,
517
+ ...rest
518
+ }
519
+ ),
520
+ /* @__PURE__ */ jsx(
521
+ Box,
522
+ {
523
+ as: "span",
524
+ className: "sui-CheckboxMark",
525
+ position: "relative",
526
+ radius: 2,
527
+ width: "17px",
528
+ height: "17px",
529
+ children: indeterminate ? /* @__PURE__ */ jsx(RemoveIcon, {}) : /* @__PURE__ */ jsx(CheckmarkIcon, {})
530
+ }
531
+ ),
532
+ label
533
+ ]
534
+ }
535
+ );
536
+ }
537
+ const CODE_TAG = ["pre", "span"], CODE_SIZE = [0, 1, 2, 3, 4], codeProps = {
419
538
  as: {
420
539
  type: "union",
421
540
  values: CODE_TAG
@@ -661,36 +780,92 @@ function Icon({ icon: Component, size = 2, ...props }) {
661
780
  }
662
781
  );
663
782
  }
664
- const TEXT_SIZE = [0, 1, 2, 3, 4], textProps = {
665
- as: {
783
+ const radioProps = {
784
+ label: {
666
785
  type: "string"
667
786
  },
668
- size: {
669
- type: "union",
670
- className: "text-body",
671
- values: TEXT_SIZE
787
+ ...marginProps
788
+ };
789
+ function Radio(props) {
790
+ const { className, style, label, ...rest } = getProps(props, radioProps);
791
+ return /* @__PURE__ */ jsxs(
792
+ Label,
793
+ {
794
+ className: classNames("sui-Radio", className),
795
+ style,
796
+ "data-ui": "Radio",
797
+ disabled: props.disabled,
798
+ children: [
799
+ /* @__PURE__ */ jsx(VisuallyHidden, { as: "input", type: "radio", className: "sui-RadioInput", ...rest }),
800
+ /* @__PURE__ */ jsx(
801
+ Box,
802
+ {
803
+ as: "span",
804
+ className: "sui-RadioMark",
805
+ position: "relative",
806
+ radius: "full",
807
+ width: "17px",
808
+ height: "17px"
809
+ }
810
+ ),
811
+ label
812
+ ]
813
+ }
814
+ );
815
+ }
816
+ const switchProps = {
817
+ label: {
818
+ type: "string"
672
819
  },
673
- ...typographyProps
820
+ indeterminate: {
821
+ type: "boolean"
822
+ },
823
+ ...marginProps
674
824
  };
675
- function Text({
676
- size = 2,
677
- ...props
678
- }) {
679
- const { as, children, className, style, ...rest } = getProps({ size, ...props }, textProps), Component = as || "span";
680
- return props.lineClamp && props.trim ? /* @__PURE__ */ jsx(
681
- Component,
825
+ function Switch(props) {
826
+ const inputRef = useRef(null), { className, style, label, indeterminate, ...rest } = getProps(props, switchProps);
827
+ return useEffect(() => {
828
+ inputRef.current && (inputRef.current.indeterminate = indeterminate);
829
+ }, [indeterminate]), /* @__PURE__ */ jsxs(
830
+ Label,
682
831
  {
683
- className: classNames("sui-Text", className?.replace("sui-line-clamp", "")),
832
+ className: classNames("sui-Switch", className),
684
833
  style,
685
- "data-ui": "Text",
686
- ...rest,
687
- children: /* @__PURE__ */ jsx("span", { className: "sui-line-clamp", children })
834
+ "data-ui": "Switch",
835
+ disabled: props.disabled,
836
+ children: [
837
+ /* @__PURE__ */ jsx(
838
+ VisuallyHidden,
839
+ {
840
+ as: "input",
841
+ type: "checkbox",
842
+ role: "switch",
843
+ className: "sui-SwitchInput",
844
+ ref: inputRef,
845
+ ...rest
846
+ }
847
+ ),
848
+ /* @__PURE__ */ jsx(
849
+ Box,
850
+ {
851
+ as: "span",
852
+ className: "sui-SwitchMark",
853
+ position: "relative",
854
+ radius: 6,
855
+ width: "25px",
856
+ height: "17px",
857
+ "aria-hidden": "true"
858
+ }
859
+ ),
860
+ label
861
+ ]
688
862
  }
689
- ) : /* @__PURE__ */ jsx(Component, { className: classNames("sui-Text", className), style, "data-ui": "Text", ...rest, children });
863
+ );
690
864
  }
691
865
  export {
692
866
  Box,
693
867
  Card,
868
+ Checkbox,
694
869
  Code,
695
870
  Container,
696
871
  Divider,
@@ -698,6 +873,10 @@ export {
698
873
  Grid,
699
874
  Heading,
700
875
  Icon,
701
- Text
876
+ Label,
877
+ Radio,
878
+ Switch,
879
+ Text,
880
+ VisuallyHidden
702
881
  };
703
882
  //# sourceMappingURL=index.js.map