@shipfox/react-ui 0.7.0 → 0.9.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 (68) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/.turbo/turbo-check.log +3 -3
  3. package/.turbo/turbo-type.log +2 -2
  4. package/CHANGELOG.md +13 -0
  5. package/dist/components/alert/alert.d.ts +15 -5
  6. package/dist/components/alert/alert.d.ts.map +1 -1
  7. package/dist/components/alert/alert.js +122 -22
  8. package/dist/components/alert/alert.js.map +1 -1
  9. package/dist/components/alert/alert.stories.js +121 -6
  10. package/dist/components/alert/alert.stories.js.map +1 -1
  11. package/dist/components/button/button-link.js +1 -1
  12. package/dist/components/button/button-link.js.map +1 -1
  13. package/dist/components/button/button.d.ts +2 -1
  14. package/dist/components/button/button.d.ts.map +1 -1
  15. package/dist/components/button/button.js +21 -3
  16. package/dist/components/button/button.js.map +1 -1
  17. package/dist/components/button/button.stories.js +25 -0
  18. package/dist/components/button/button.stories.js.map +1 -1
  19. package/dist/components/button/icon-button.d.ts +2 -1
  20. package/dist/components/button/icon-button.d.ts.map +1 -1
  21. package/dist/components/button/icon-button.js +21 -3
  22. package/dist/components/button/icon-button.js.map +1 -1
  23. package/dist/components/button/icon-button.stories.js +90 -0
  24. package/dist/components/button/icon-button.stories.js.map +1 -1
  25. package/dist/components/checkbox/checkbox-links.d.ts.map +1 -1
  26. package/dist/components/checkbox/checkbox-links.js +8 -2
  27. package/dist/components/checkbox/checkbox-links.js.map +1 -1
  28. package/dist/components/checkbox/checkbox.stories.js +4 -4
  29. package/dist/components/checkbox/checkbox.stories.js.map +1 -1
  30. package/dist/components/form/form.d.ts +11 -0
  31. package/dist/components/form/form.d.ts.map +1 -0
  32. package/dist/components/form/form.js +106 -0
  33. package/dist/components/form/form.js.map +1 -0
  34. package/dist/components/form/form.stories.js +582 -0
  35. package/dist/components/form/form.stories.js.map +1 -0
  36. package/dist/components/form/index.d.ts +2 -0
  37. package/dist/components/form/index.d.ts.map +1 -0
  38. package/dist/components/form/index.js +3 -0
  39. package/dist/components/form/index.js.map +1 -0
  40. package/dist/components/icon/custom/spinner.d.ts +1 -1
  41. package/dist/components/icon/custom/spinner.d.ts.map +1 -1
  42. package/dist/components/icon/custom/spinner.js +84 -30
  43. package/dist/components/icon/custom/spinner.js.map +1 -1
  44. package/dist/components/icon/icon.d.ts +19 -18
  45. package/dist/components/icon/icon.d.ts.map +1 -1
  46. package/dist/components/icon/icon.js +17 -17
  47. package/dist/components/icon/icon.js.map +1 -1
  48. package/dist/components/index.d.ts +1 -0
  49. package/dist/components/index.d.ts.map +1 -1
  50. package/dist/components/index.js +1 -0
  51. package/dist/components/index.js.map +1 -1
  52. package/dist/styles.css +1 -1
  53. package/package.json +3 -1
  54. package/src/components/alert/alert.stories.tsx +103 -2
  55. package/src/components/alert/alert.tsx +163 -16
  56. package/src/components/button/button-link.tsx +1 -1
  57. package/src/components/button/button.stories.tsx +18 -0
  58. package/src/components/button/button.tsx +29 -3
  59. package/src/components/button/icon-button.stories.tsx +46 -0
  60. package/src/components/button/icon-button.tsx +28 -2
  61. package/src/components/checkbox/checkbox-links.tsx +5 -3
  62. package/src/components/checkbox/checkbox.stories.tsx +20 -4
  63. package/src/components/form/form.stories.tsx +500 -0
  64. package/src/components/form/form.tsx +154 -0
  65. package/src/components/form/index.ts +1 -0
  66. package/src/components/icon/custom/spinner.tsx +64 -18
  67. package/src/components/icon/icon.tsx +18 -18
  68. package/src/components/index.ts +1 -0
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Slot } from '@radix-ui/react-slot';
3
+ import { Label } from '../../components/label/index.js';
4
+ import * as React from 'react';
5
+ import { Controller, FormProvider, useFormContext } from 'react-hook-form';
6
+ import { cn } from '../../utils/cn.js';
7
+ const Form = FormProvider;
8
+ const FormFieldContext = /*#__PURE__*/ React.createContext(null);
9
+ const FormItemContext = /*#__PURE__*/ React.createContext(null);
10
+ const FormField = ({ ...props })=>{
11
+ return /*#__PURE__*/ _jsx(FormFieldContext.Provider, {
12
+ value: {
13
+ name: props.name
14
+ },
15
+ children: /*#__PURE__*/ _jsx(Controller, {
16
+ ...props
17
+ })
18
+ });
19
+ };
20
+ const useFormField = ()=>{
21
+ const fieldContext = React.useContext(FormFieldContext);
22
+ const itemContext = React.useContext(FormItemContext);
23
+ const { getFieldState, formState } = useFormContext();
24
+ if (!fieldContext) {
25
+ throw new Error('useFormField should be used within <FormField>');
26
+ }
27
+ if (!itemContext) {
28
+ throw new Error('useFormField should be used within <FormItem>');
29
+ }
30
+ const fieldState = getFieldState(fieldContext.name, formState);
31
+ const { id } = itemContext;
32
+ return {
33
+ id,
34
+ name: fieldContext.name,
35
+ formItemId: `${id}-form-item`,
36
+ formDescriptionId: `${id}-form-item-description`,
37
+ formMessageId: `${id}-form-item-message`,
38
+ ...fieldState
39
+ };
40
+ };
41
+ const FormItem = /*#__PURE__*/ React.forwardRef(({ className, ...props }, ref)=>{
42
+ const id = React.useId();
43
+ return /*#__PURE__*/ _jsx(FormItemContext.Provider, {
44
+ value: {
45
+ id
46
+ },
47
+ children: /*#__PURE__*/ _jsx("div", {
48
+ ref: ref,
49
+ className: className,
50
+ ...props
51
+ })
52
+ });
53
+ });
54
+ FormItem.displayName = 'FormItem';
55
+ const FormLabel = /*#__PURE__*/ React.forwardRef(({ className, ...props }, ref)=>{
56
+ const { error, formItemId } = useFormField();
57
+ return /*#__PURE__*/ _jsx(Label, {
58
+ ref: ref,
59
+ className: cn(error && 'text-foreground-error', className),
60
+ htmlFor: formItemId,
61
+ ...props
62
+ });
63
+ });
64
+ FormLabel.displayName = 'FormLabel';
65
+ const FormControl = /*#__PURE__*/ React.forwardRef(({ ...props }, ref)=>{
66
+ const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
67
+ return /*#__PURE__*/ _jsx(Slot, {
68
+ ref: ref,
69
+ id: formItemId,
70
+ "aria-describedby": error ? formMessageId : formDescriptionId,
71
+ "aria-invalid": !!error,
72
+ ...props
73
+ });
74
+ });
75
+ FormControl.displayName = 'FormControl';
76
+ const FormDescription = /*#__PURE__*/ React.forwardRef(({ className, ...props }, ref)=>{
77
+ const { error, formDescriptionId } = useFormField();
78
+ if (error) {
79
+ return null;
80
+ }
81
+ return /*#__PURE__*/ _jsx("p", {
82
+ ref: ref,
83
+ id: formDescriptionId,
84
+ className: cn('text-sm text-foreground-neutral-muted', className),
85
+ ...props
86
+ });
87
+ });
88
+ FormDescription.displayName = 'FormDescription';
89
+ const FormMessage = /*#__PURE__*/ React.forwardRef(({ className, children, ...props }, ref)=>{
90
+ const { error, formMessageId } = useFormField();
91
+ const body = error ? String(error?.message ?? '') : children;
92
+ if (!body) {
93
+ return null;
94
+ }
95
+ return /*#__PURE__*/ _jsx("p", {
96
+ ref: ref,
97
+ id: formMessageId,
98
+ className: cn('text-sm font-medium text-foreground-highlight-error', className),
99
+ ...props,
100
+ children: body
101
+ });
102
+ });
103
+ FormMessage.displayName = 'FormMessage';
104
+ export { Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage };
105
+
106
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/form/form.tsx"],"sourcesContent":["import {Slot} from '@radix-ui/react-slot';\nimport {Label} from 'components/label';\nimport type {ComponentProps} from 'react';\nimport * as React from 'react';\nimport type {ControllerProps, FieldPath, FieldValues} from 'react-hook-form';\nimport {Controller, FormProvider, useFormContext} from 'react-hook-form';\nimport {cn} from 'utils/cn';\n\nconst Form = FormProvider;\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = {\n name: TName;\n};\n\ntype FormItemContextValue = {\n id: string;\n};\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{name: props.name}}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n};\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const {getFieldState, formState} = useFormContext();\n\n if (!fieldContext) {\n throw new Error('useFormField should be used within <FormField>');\n }\n\n if (!itemContext) {\n throw new Error('useFormField should be used within <FormItem>');\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n const {id} = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n };\n};\n\nconst FormItem = React.forwardRef<HTMLDivElement, ComponentProps<'div'>>(\n ({className, ...props}, ref) => {\n const id = React.useId();\n\n return (\n <FormItemContext.Provider value={{id}}>\n <div ref={ref} className={className} {...props} />\n </FormItemContext.Provider>\n );\n },\n);\nFormItem.displayName = 'FormItem';\n\nconst FormLabel = React.forwardRef<React.ElementRef<typeof Label>, ComponentProps<typeof Label>>(\n ({className, ...props}, ref) => {\n const {error, formItemId} = useFormField();\n\n return (\n <Label\n ref={ref}\n className={cn(error && 'text-foreground-error', className)}\n htmlFor={formItemId}\n {...props}\n />\n );\n },\n);\nFormLabel.displayName = 'FormLabel';\n\nconst FormControl = React.forwardRef<React.ElementRef<typeof Slot>, ComponentProps<typeof Slot>>(\n ({...props}, ref) => {\n const {error, formItemId, formDescriptionId, formMessageId} = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={error ? formMessageId : formDescriptionId}\n aria-invalid={!!error}\n {...props}\n />\n );\n },\n);\nFormControl.displayName = 'FormControl';\n\nconst FormDescription = React.forwardRef<HTMLParagraphElement, ComponentProps<'p'>>(\n ({className, ...props}, ref) => {\n const {error, formDescriptionId} = useFormField();\n\n if (error) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn('text-sm text-foreground-neutral-muted', className)}\n {...props}\n />\n );\n },\n);\nFormDescription.displayName = 'FormDescription';\n\nconst FormMessage = React.forwardRef<HTMLParagraphElement, ComponentProps<'p'>>(\n ({className, children, ...props}, ref) => {\n const {error, formMessageId} = useFormField();\n const body = error ? String(error?.message ?? '') : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn('text-sm font-medium text-foreground-highlight-error', className)}\n {...props}\n >\n {body}\n </p>\n );\n },\n);\nFormMessage.displayName = 'FormMessage';\n\nexport {Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage};\n"],"names":["Slot","Label","React","Controller","FormProvider","useFormContext","cn","Form","FormFieldContext","createContext","FormItemContext","FormField","props","Provider","value","name","useFormField","fieldContext","useContext","itemContext","getFieldState","formState","Error","fieldState","id","formItemId","formDescriptionId","formMessageId","FormItem","forwardRef","className","ref","useId","div","displayName","FormLabel","error","htmlFor","FormControl","aria-describedby","aria-invalid","FormDescription","p","FormMessage","children","body","String","message"],"mappings":";AAAA,SAAQA,IAAI,QAAO,uBAAuB;AAC1C,SAAQC,KAAK,QAAO,mBAAmB;AAEvC,YAAYC,WAAW,QAAQ;AAE/B,SAAQC,UAAU,EAAEC,YAAY,EAAEC,cAAc,QAAO,kBAAkB;AACzE,SAAQC,EAAE,QAAO,WAAW;AAE5B,MAAMC,OAAOH;AAab,MAAMI,iCAAmBN,MAAMO,aAAa,CAA+B;AAE3E,MAAMC,gCAAkBR,MAAMO,aAAa,CAA8B;AAEzE,MAAME,YAAY,CAGhB,EACA,GAAGC,OACkC;IACrC,qBACE,KAACJ,iBAAiBK,QAAQ;QAACC,OAAO;YAACC,MAAMH,MAAMG,IAAI;QAAA;kBACjD,cAAA,KAACZ;YAAY,GAAGS,KAAK;;;AAG3B;AAEA,MAAMI,eAAe;IACnB,MAAMC,eAA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