@cerberus-design/react 0.15.0-next-e0ce56e → 0.15.0-next-739c492
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.
- package/build/legacy/_tsup-dts-rollup.d.cts +313 -112
- package/build/legacy/components/Checkbox.cjs +27 -35
- package/build/legacy/components/Checkbox.cjs.map +1 -1
- package/build/legacy/components/DatePicker.client.cjs +67 -89
- package/build/legacy/components/DatePicker.client.cjs.map +1 -1
- package/build/legacy/components/Fieldset.cjs +4 -17
- package/build/legacy/components/Fieldset.cjs.map +1 -1
- package/build/legacy/components/FieldsetLabel.cjs.map +1 -1
- package/build/legacy/components/FileStatus.cjs +126 -79
- package/build/legacy/components/FileStatus.cjs.map +1 -1
- package/build/legacy/components/Legend.cjs +10 -22
- package/build/legacy/components/Legend.cjs.map +1 -1
- package/build/legacy/components/Radio.cjs +4 -21
- package/build/legacy/components/Radio.cjs.map +1 -1
- package/build/legacy/components/Select.cjs +19 -54
- package/build/legacy/components/Select.cjs.map +1 -1
- package/build/legacy/components/Toggle.cjs +17 -24
- package/build/legacy/components/Toggle.cjs.map +1 -1
- package/build/legacy/components/button/button.cjs +1 -1
- package/build/legacy/components/button/button.cjs.map +1 -1
- package/build/legacy/components/button/index.cjs +1 -1
- package/build/legacy/components/button/index.cjs.map +1 -1
- package/build/legacy/components/button/parts.cjs +1 -1
- package/build/legacy/components/button/parts.cjs.map +1 -1
- package/build/legacy/components/{FieldMessage.cjs → deprecated/FieldMessage.cjs} +4 -17
- package/build/legacy/components/deprecated/FieldMessage.cjs.map +1 -0
- package/build/legacy/components/{Textarea.cjs → deprecated/Label.cjs} +24 -36
- package/build/legacy/components/deprecated/Label.cjs.map +1 -0
- package/build/legacy/components/field/field.cjs +130 -0
- package/build/legacy/components/field/field.cjs.map +1 -0
- package/build/legacy/components/field/index.cjs +261 -0
- package/build/legacy/components/field/index.cjs.map +1 -0
- package/build/legacy/components/field/parts.cjs +184 -0
- package/build/legacy/components/field/parts.cjs.map +1 -0
- package/build/legacy/components/field/primitives.cjs +186 -0
- package/build/legacy/components/field/primitives.cjs.map +1 -0
- package/build/legacy/components/field/start-indicator.cjs +45 -0
- package/build/legacy/components/field/start-indicator.cjs.map +1 -0
- package/build/legacy/components/field/status-indicator.cjs +78 -0
- package/build/legacy/components/field/status-indicator.cjs.map +1 -0
- package/build/legacy/context/confirm-modal.cjs +1 -1
- package/build/legacy/context/confirm-modal.cjs.map +1 -1
- package/build/legacy/context/cta-modal.cjs +1 -1
- package/build/legacy/context/cta-modal.cjs.map +1 -1
- package/build/legacy/context/field.cjs +23 -4
- package/build/legacy/context/field.cjs.map +1 -1
- package/build/legacy/context/notification-center.cjs.map +1 -1
- package/build/legacy/context/prompt-modal.cjs +168 -166
- package/build/legacy/context/prompt-modal.cjs.map +1 -1
- package/build/legacy/hooks/useDate.cjs.map +1 -1
- package/build/legacy/index.cjs +1156 -1067
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/utils/index.cjs +22 -2
- package/build/legacy/utils/index.cjs.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +313 -112
- package/build/modern/{chunk-2JX27W6Y.js → chunk-2BIHLH4V.js} +2 -2
- package/build/modern/chunk-2BIHLH4V.js.map +1 -0
- package/build/modern/{chunk-3ZDFQO25.js → chunk-6EUC3SUI.js} +4 -7
- package/build/modern/chunk-6EUC3SUI.js.map +1 -0
- package/build/modern/{chunk-MER66QUY.js → chunk-6KZVE4HC.js} +1 -1
- package/build/modern/{chunk-MER66QUY.js.map → chunk-6KZVE4HC.js.map} +1 -1
- package/build/modern/{chunk-FTPZHG6J.js → chunk-6WOJAMZV.js} +3 -9
- package/build/modern/chunk-6WOJAMZV.js.map +1 -0
- package/build/modern/chunk-7VA5SXTY.js +31 -0
- package/build/modern/chunk-7VA5SXTY.js.map +1 -0
- package/build/modern/chunk-7YVOZULL.js +23 -0
- package/build/modern/chunk-7YVOZULL.js.map +1 -0
- package/build/modern/{chunk-KU2AWAK3.js → chunk-B2A6QFKT.js} +4 -17
- package/build/modern/chunk-B2A6QFKT.js.map +1 -0
- package/build/modern/chunk-BL7G3577.js +29 -0
- package/build/modern/chunk-BL7G3577.js.map +1 -0
- package/build/modern/chunk-C5NL3X7W.js +96 -0
- package/build/modern/chunk-C5NL3X7W.js.map +1 -0
- package/build/modern/chunk-CNA2VKAH.js +43 -0
- package/build/modern/chunk-CNA2VKAH.js.map +1 -0
- package/build/modern/{chunk-Z7FGXAND.js → chunk-FMRWRVUS.js} +2 -2
- package/build/modern/{chunk-NGOLRISW.js → chunk-FVE4GBB7.js} +9 -8
- package/build/modern/chunk-FVE4GBB7.js.map +1 -0
- package/build/modern/{chunk-7P7OWBGV.js → chunk-G2VFEBY4.js} +8 -8
- package/build/modern/chunk-G2VFEBY4.js.map +1 -0
- package/build/modern/{chunk-XQICKZH4.js → chunk-GENS32QO.js} +10 -8
- package/build/modern/chunk-GENS32QO.js.map +1 -0
- package/build/modern/{chunk-Q4IV5NUT.js → chunk-GNPGG4ND.js} +37 -40
- package/build/modern/chunk-GNPGG4ND.js.map +1 -0
- package/build/modern/{chunk-7S47NSGR.js → chunk-H54FR7IP.js} +2 -2
- package/build/modern/chunk-IGSC4IEA.js +37 -0
- package/build/modern/chunk-IGSC4IEA.js.map +1 -0
- package/build/modern/{chunk-JWIJHSI6.js → chunk-L7N24B6B.js} +3 -6
- package/build/modern/chunk-L7N24B6B.js.map +1 -0
- package/build/modern/{chunk-3RGRHMJQ.js → chunk-LCN7LYTU.js} +5 -5
- package/build/modern/{chunk-3BM6MZ4A.js → chunk-MWRO5QYD.js} +1 -1
- package/build/modern/chunk-MWRO5QYD.js.map +1 -0
- package/build/modern/{chunk-PZAZKQMO.js → chunk-OYT7RGC7.js} +1 -1
- package/build/modern/chunk-OYT7RGC7.js.map +1 -0
- package/build/modern/{chunk-ILQW5VZT.js → chunk-RBNOEAWJ.js} +4 -7
- package/build/modern/chunk-RBNOEAWJ.js.map +1 -0
- package/build/modern/{chunk-5QONP7GT.js → chunk-S2X5OEPK.js} +2 -10
- package/build/modern/chunk-S2X5OEPK.js.map +1 -0
- package/build/modern/chunk-TYPULJMJ.js +1 -0
- package/build/modern/chunk-Z52R6ABJ.js +21 -0
- package/build/modern/chunk-Z52R6ABJ.js.map +1 -0
- package/build/modern/components/Checkbox.js +1 -2
- package/build/modern/components/DatePicker.client.js +3 -4
- package/build/modern/components/Fieldset.js +1 -2
- package/build/modern/components/FieldsetLabel.js +1 -1
- package/build/modern/components/FileStatus.js +9 -3
- package/build/modern/components/Legend.js +1 -2
- package/build/modern/components/Radio.js +1 -3
- package/build/modern/components/Select.js +1 -2
- package/build/modern/components/Toggle.js +1 -2
- package/build/modern/components/button/button.js +1 -1
- package/build/modern/components/button/index.js +2 -2
- package/build/modern/components/button/parts.js +2 -2
- package/build/modern/components/deprecated/FieldMessage.js +8 -0
- package/build/modern/components/deprecated/Label.js +17 -0
- package/build/modern/components/field/field.js +14 -0
- package/build/modern/components/field/index.js +42 -0
- package/build/modern/components/field/index.js.map +1 -0
- package/build/modern/components/field/parts.js +11 -0
- package/build/modern/components/field/parts.js.map +1 -0
- package/build/modern/components/field/primitives.js +24 -0
- package/build/modern/components/field/primitives.js.map +1 -0
- package/build/modern/components/field/start-indicator.js +7 -0
- package/build/modern/components/field/start-indicator.js.map +1 -0
- package/build/modern/components/field/status-indicator.js +9 -0
- package/build/modern/components/field/status-indicator.js.map +1 -0
- package/build/modern/context/confirm-modal.js +2 -2
- package/build/modern/context/cta-modal.js +4 -4
- package/build/modern/context/field.js +34 -4
- package/build/modern/context/field.js.map +1 -1
- package/build/modern/context/notification-center.js +2 -2
- package/build/modern/context/prompt-modal.js +10 -5
- package/build/modern/hooks/useDate.js +1 -1
- package/build/modern/index.js +85 -62
- package/build/modern/index.js.map +1 -1
- package/build/modern/utils/index.js +5 -3
- package/package.json +2 -2
- package/src/components/Checkbox.tsx +13 -9
- package/src/components/DatePicker.client.tsx +2 -14
- package/src/components/Fieldset.tsx +3 -3
- package/src/components/FieldsetLabel.tsx +5 -2
- package/src/components/FileStatus.tsx +4 -5
- package/src/components/Legend.tsx +5 -6
- package/src/components/Radio.tsx +2 -7
- package/src/components/Select.tsx +1 -16
- package/src/components/Toggle.tsx +14 -7
- package/src/components/button/button.tsx +1 -1
- package/src/components/button/parts.ts +6 -0
- package/src/components/{FieldMessage.tsx → deprecated/FieldMessage.tsx} +2 -13
- package/src/components/deprecated/Label.tsx +24 -0
- package/src/components/field/field.tsx +77 -0
- package/src/components/field/index.ts +5 -0
- package/src/components/field/parts.ts +71 -0
- package/src/components/field/primitives.tsx +197 -0
- package/src/components/field/start-indicator.tsx +23 -0
- package/src/components/field/status-indicator.tsx +58 -0
- package/src/context/field.tsx +6 -5
- package/src/context/prompt-modal.tsx +16 -18
- package/src/hooks/useDate.ts +1 -7
- package/src/index.ts +4 -6
- package/src/utils/index.ts +30 -0
- package/build/legacy/components/FieldMessage.cjs.map +0 -1
- package/build/legacy/components/Input.cjs +0 -95
- package/build/legacy/components/Input.cjs.map +0 -1
- package/build/legacy/components/Label.cjs +0 -93
- package/build/legacy/components/Label.cjs.map +0 -1
- package/build/legacy/components/Textarea.cjs.map +0 -1
- package/build/modern/chunk-2JX27W6Y.js.map +0 -1
- package/build/modern/chunk-3BM6MZ4A.js.map +0 -1
- package/build/modern/chunk-3ZDFQO25.js.map +0 -1
- package/build/modern/chunk-5QONP7GT.js.map +0 -1
- package/build/modern/chunk-7P7OWBGV.js.map +0 -1
- package/build/modern/chunk-C5EHJUS5.js +0 -10
- package/build/modern/chunk-C5EHJUS5.js.map +0 -1
- package/build/modern/chunk-FTPZHG6J.js.map +0 -1
- package/build/modern/chunk-ILQW5VZT.js.map +0 -1
- package/build/modern/chunk-JIJM6JFJ.js +0 -36
- package/build/modern/chunk-JIJM6JFJ.js.map +0 -1
- package/build/modern/chunk-JWIJHSI6.js.map +0 -1
- package/build/modern/chunk-KU2AWAK3.js.map +0 -1
- package/build/modern/chunk-NGOLRISW.js.map +0 -1
- package/build/modern/chunk-NMF2HYWO.js +0 -50
- package/build/modern/chunk-NMF2HYWO.js.map +0 -1
- package/build/modern/chunk-PZAZKQMO.js.map +0 -1
- package/build/modern/chunk-Q4IV5NUT.js.map +0 -1
- package/build/modern/chunk-UZDVOIW5.js +0 -33
- package/build/modern/chunk-UZDVOIW5.js.map +0 -1
- package/build/modern/chunk-VYCU7I4J.js +0 -43
- package/build/modern/chunk-VYCU7I4J.js.map +0 -1
- package/build/modern/chunk-XQICKZH4.js.map +0 -1
- package/build/modern/components/FieldMessage.js +0 -9
- package/build/modern/components/Input.js +0 -11
- package/build/modern/components/Label.js +0 -10
- package/build/modern/components/Textarea.js +0 -9
- package/src/components/Input.tsx +0 -69
- package/src/components/Label.tsx +0 -69
- package/src/components/Textarea.tsx +0 -52
- /package/build/modern/{chunk-Z7FGXAND.js.map → chunk-FMRWRVUS.js.map} +0 -0
- /package/build/modern/{chunk-7S47NSGR.js.map → chunk-H54FR7IP.js.map} +0 -0
- /package/build/modern/{chunk-3RGRHMJQ.js.map → chunk-LCN7LYTU.js.map} +0 -0
- /package/build/modern/{components/FieldMessage.js.map → chunk-TYPULJMJ.js.map} +0 -0
- /package/build/modern/components/{Input.js.map → deprecated/FieldMessage.js.map} +0 -0
- /package/build/modern/components/{Label.js.map → deprecated/Label.js.map} +0 -0
- /package/build/modern/components/{Textarea.js.map → field/field.js.map} +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
type FieldHelperTextProps,
|
|
4
|
+
type FieldInputProps as ArkFieldInputProps,
|
|
5
|
+
type FieldLabelProps,
|
|
6
|
+
type FieldRootProps as ArkFieldRootProps,
|
|
7
|
+
type FieldTextareaProps,
|
|
8
|
+
} from '@ark-ui/react/field'
|
|
9
|
+
import type { ReactNode } from 'react'
|
|
10
|
+
import { cx } from '@cerberus/styled-system/css'
|
|
11
|
+
import { field, type FieldVariantProps } from '@cerberus/styled-system/recipes'
|
|
12
|
+
import { FieldStatusIndicator } from './status-indicator'
|
|
13
|
+
import { FieldStartIndicator } from './start-indicator'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This module contains all the primitives of the Field component.
|
|
17
|
+
* @module 'field'
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export type FieldRootProps = ArkFieldRootProps & FieldVariantProps
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The context & container for the Field components.
|
|
24
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <FieldRoot required ids={{ input: 'exampleId' }}>
|
|
28
|
+
* <FieldLabel>Label</FieldLabel>
|
|
29
|
+
* <FieldInput />
|
|
30
|
+
* </FieldRoot>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function FieldRoot(props: FieldRootProps) {
|
|
34
|
+
const { size, ...fieldProps } = props
|
|
35
|
+
const styles = field({ size })
|
|
36
|
+
return (
|
|
37
|
+
<Field.Root
|
|
38
|
+
{...fieldProps}
|
|
39
|
+
className={cx(styles.root, fieldProps.className)}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The label for the Field component.
|
|
46
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <FieldRoot>
|
|
50
|
+
* <FieldLabel>Label</FieldLabel>
|
|
51
|
+
* </FieldRoot>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function FieldLabel(props: FieldLabelProps) {
|
|
55
|
+
const { children, ...nativeProps } = props
|
|
56
|
+
const styles = field()
|
|
57
|
+
return (
|
|
58
|
+
<Field.Label {...nativeProps} className={cx(styles.label, props.className)}>
|
|
59
|
+
{children}
|
|
60
|
+
<Field.RequiredIndicator>(required)</Field.RequiredIndicator>
|
|
61
|
+
</Field.Label>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface FieldInputProps
|
|
66
|
+
extends Omit<ArkFieldInputProps, 'size'>,
|
|
67
|
+
FieldVariantProps {
|
|
68
|
+
/**
|
|
69
|
+
* An optional icon to display at the start of the input.
|
|
70
|
+
*/
|
|
71
|
+
startIcon?: ReactNode
|
|
72
|
+
/**
|
|
73
|
+
* An optional icon to display at the end of the input.
|
|
74
|
+
*/
|
|
75
|
+
endIcon?: ReactNode
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The input for the Field component.
|
|
80
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* <FieldRoot>
|
|
84
|
+
* <FieldInput />
|
|
85
|
+
* </FieldRoot>
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export function FieldInput(props: FieldInputProps) {
|
|
89
|
+
const { size, startIcon, endIcon, ...fieldProps } = props
|
|
90
|
+
const styles = field({ size })
|
|
91
|
+
const hasStartIcon = Boolean(startIcon)
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div className={styles.inputRoot}>
|
|
95
|
+
<FieldStartIndicator>{startIcon}</FieldStartIndicator>
|
|
96
|
+
<Field.Input
|
|
97
|
+
{...fieldProps}
|
|
98
|
+
{...(hasStartIcon && { 'data-has': 'start-indicator' })}
|
|
99
|
+
className={cx(styles.input, fieldProps.className)}
|
|
100
|
+
/>
|
|
101
|
+
<FieldStatusIndicator fallback={endIcon} />
|
|
102
|
+
</div>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The helper text for the Field component that is shown when the field is
|
|
108
|
+
* valid.
|
|
109
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* <FieldRoot>
|
|
113
|
+
* <FieldInput />
|
|
114
|
+
* <FieldHelperText>Helper text</FieldHelperText>
|
|
115
|
+
* </FieldRoot>
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export function FieldHelperText(props: FieldHelperTextProps) {
|
|
119
|
+
const styles = field()
|
|
120
|
+
|
|
121
|
+
if (!props.children) return null
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Field.HelperText
|
|
125
|
+
{...props}
|
|
126
|
+
className={cx(styles.helperText, props.className)}
|
|
127
|
+
/>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The error text for the Field component that is shown when the field is
|
|
133
|
+
* invalid.
|
|
134
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* <FieldRoot>
|
|
138
|
+
* <FieldInput />
|
|
139
|
+
* <FieldErrorText>Error text</FieldErrorText>
|
|
140
|
+
* </FieldRoot>
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export function FieldErrorText(props: FieldHelperTextProps) {
|
|
144
|
+
const styles = field()
|
|
145
|
+
|
|
146
|
+
if (!props.children) return null
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<Field.ErrorText
|
|
150
|
+
{...props}
|
|
151
|
+
className={cx(styles.errorText, props.className)}
|
|
152
|
+
/>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The textarea for the Field component.
|
|
158
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* <FieldRoot>
|
|
162
|
+
* <FieldTextarea />
|
|
163
|
+
* </FieldRoot>
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export function FieldTextarea(props: FieldTextareaProps) {
|
|
167
|
+
const styles = field()
|
|
168
|
+
return (
|
|
169
|
+
<Field.Textarea
|
|
170
|
+
{...props}
|
|
171
|
+
className={cx(styles.textarea, props.className)}
|
|
172
|
+
/>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A named export for the FieldInput component.
|
|
178
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
179
|
+
* @example
|
|
180
|
+
* ```tsx
|
|
181
|
+
* import { Input } from '@cerberus/react'
|
|
182
|
+
*
|
|
183
|
+
* <Field
|
|
184
|
+
* ids={{
|
|
185
|
+
* control: 'email',
|
|
186
|
+
* }}
|
|
187
|
+
* label="Enter your email"
|
|
188
|
+
* helperText="We'll never share your email with anyone else."
|
|
189
|
+
* errorText="Email is required."
|
|
190
|
+
* required
|
|
191
|
+
* >
|
|
192
|
+
* <Input type="email" />
|
|
193
|
+
* </Field>
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export const Input = FieldInput
|
|
197
|
+
export const Textarea = FieldTextarea
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { cx } from '@cerberus/styled-system/css'
|
|
2
|
+
import { field } from '@cerberus/styled-system/recipes'
|
|
3
|
+
import type { HTMLAttributes } from 'react'
|
|
4
|
+
|
|
5
|
+
export type FieldIndicatorProps = HTMLAttributes<HTMLSpanElement>
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The start indicator displays an indicator at the start of the Input.
|
|
9
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
10
|
+
*/
|
|
11
|
+
export function FieldStartIndicator(props: FieldIndicatorProps) {
|
|
12
|
+
const styles = field()
|
|
13
|
+
|
|
14
|
+
if (!props.children) return null
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<span
|
|
18
|
+
{...props}
|
|
19
|
+
data-part="start-indicator"
|
|
20
|
+
className={cx(props.className, styles.startIndicator)}
|
|
21
|
+
/>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useFieldContext } from '@ark-ui/react'
|
|
4
|
+
import { cx } from '@cerberus/styled-system/css'
|
|
5
|
+
import { field } from '@cerberus/styled-system/recipes'
|
|
6
|
+
import { useCerberusContext } from '../../context/cerberus'
|
|
7
|
+
import type { HTMLAttributes, ReactNode } from 'react'
|
|
8
|
+
|
|
9
|
+
export interface FieldStatusIndicatorProps
|
|
10
|
+
extends HTMLAttributes<HTMLSpanElement> {
|
|
11
|
+
/**
|
|
12
|
+
* The fallback content to display when the field is valid.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: ReactNode
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The invalid status indicator for the Field component.
|
|
19
|
+
* @description [Field Docs](https://cerberus.digitalu.design/react/field)
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <FieldRoot>
|
|
23
|
+
* <FieldStatusIndicator />
|
|
24
|
+
* </FieldRoot>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function FieldStatusIndicator(props: FieldStatusIndicatorProps) {
|
|
28
|
+
const { fallback, ...nativeProps } = props
|
|
29
|
+
const styles = field()
|
|
30
|
+
const fieldContext = useFieldContext()
|
|
31
|
+
|
|
32
|
+
const { icons } = useCerberusContext()
|
|
33
|
+
const { invalid: InvalidIcon } = icons
|
|
34
|
+
|
|
35
|
+
if (fieldContext.invalid) {
|
|
36
|
+
return (
|
|
37
|
+
<span
|
|
38
|
+
{...nativeProps}
|
|
39
|
+
aria-hidden="true"
|
|
40
|
+
data-invalid
|
|
41
|
+
className={cx(nativeProps.className, styles.statusIndicator)}
|
|
42
|
+
>
|
|
43
|
+
<InvalidIcon />
|
|
44
|
+
</span>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<span
|
|
50
|
+
{...nativeProps}
|
|
51
|
+
aria-hidden="true"
|
|
52
|
+
data-part="end-indicator"
|
|
53
|
+
className={cx(nativeProps.className, styles.endIndicator)}
|
|
54
|
+
>
|
|
55
|
+
{fallback}
|
|
56
|
+
</span>
|
|
57
|
+
)
|
|
58
|
+
}
|
package/src/context/field.tsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
+
import type { FieldRootProps } from '@ark-ui/react'
|
|
3
4
|
import {
|
|
4
5
|
createContext,
|
|
5
6
|
useContext,
|
|
6
7
|
useMemo,
|
|
7
8
|
type PropsWithChildren,
|
|
8
9
|
} from 'react'
|
|
10
|
+
import { FieldRoot } from '../components/field/primitives'
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* This module provides a context and hook for the field.
|
|
@@ -35,11 +37,10 @@ export interface FieldContextValue {
|
|
|
35
37
|
const FieldContext = createContext<FieldContextValue | null>(null)
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @see https://cerberus.digitalu.design/react/input
|
|
40
|
+
* @deprecated use FieldRoot or FieldParts instead
|
|
40
41
|
*/
|
|
41
|
-
export function
|
|
42
|
-
props: PropsWithChildren<
|
|
42
|
+
export function FieldProvider(
|
|
43
|
+
props: PropsWithChildren<FieldRootProps>,
|
|
43
44
|
): JSX.Element {
|
|
44
45
|
const value = useMemo(
|
|
45
46
|
() => ({
|
|
@@ -53,7 +54,7 @@ export function Field(
|
|
|
53
54
|
|
|
54
55
|
return (
|
|
55
56
|
<FieldContext.Provider value={value}>
|
|
56
|
-
{props
|
|
57
|
+
<FieldRoot {...props} />
|
|
57
58
|
</FieldContext.Provider>
|
|
58
59
|
)
|
|
59
60
|
}
|
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
type MouseEvent,
|
|
12
12
|
type PropsWithChildren,
|
|
13
13
|
} from 'react'
|
|
14
|
-
import {
|
|
14
|
+
import { DialogCloseTrigger } from '@ark-ui/react'
|
|
15
|
+
import { HStack, VStack } from '@cerberus/styled-system/jsx'
|
|
15
16
|
import { css } from '@cerberus/styled-system/css'
|
|
16
17
|
import { hstack } from '@cerberus/styled-system/patterns'
|
|
17
|
-
import { Input } from '../components/
|
|
18
|
-
import {
|
|
19
|
-
import { Label } from '../components/Label'
|
|
18
|
+
import { FieldLabel, FieldRoot, Input } from '../components/field/index'
|
|
19
|
+
import { Button } from '../components/button/button'
|
|
20
20
|
import { Show } from '../components/Show'
|
|
21
21
|
import { Avatar } from '../components/Avatar'
|
|
22
22
|
import { Text } from '../components/Text'
|
|
@@ -27,8 +27,6 @@ import {
|
|
|
27
27
|
DialogHeading,
|
|
28
28
|
DialogProvider,
|
|
29
29
|
} from '../components/Dialog'
|
|
30
|
-
import { HStack, VStack } from '@cerberus/styled-system/jsx'
|
|
31
|
-
import { DialogCloseTrigger } from '@ark-ui/react'
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
32
|
* This module provides a context and hook for the prompt modal.
|
|
@@ -216,28 +214,28 @@ export function PromptModal(
|
|
|
216
214
|
marginBlockEnd="lg"
|
|
217
215
|
w="full"
|
|
218
216
|
>
|
|
219
|
-
<
|
|
220
|
-
|
|
217
|
+
<FieldRoot
|
|
218
|
+
ids={{
|
|
219
|
+
control: 'confirm',
|
|
220
|
+
}}
|
|
221
|
+
invalid={!isValid}
|
|
222
|
+
>
|
|
223
|
+
<FieldLabel
|
|
221
224
|
className={hstack({
|
|
222
225
|
gap: 'xs',
|
|
223
226
|
justify: 'flex-start !important',
|
|
227
|
+
marginBlockEnd: 'xs',
|
|
228
|
+
textStyle: 'label-md',
|
|
224
229
|
})}
|
|
225
|
-
htmlFor="confirm"
|
|
226
|
-
size="md"
|
|
227
230
|
>
|
|
228
231
|
Type
|
|
229
232
|
<Text as="strong" textTransform="uppercase">
|
|
230
233
|
{content?.key}
|
|
231
234
|
</Text>
|
|
232
235
|
to confirm
|
|
233
|
-
</
|
|
234
|
-
<Input
|
|
235
|
-
|
|
236
|
-
name="confirm"
|
|
237
|
-
onChange={handleChange}
|
|
238
|
-
type="text"
|
|
239
|
-
/>
|
|
240
|
-
</Field>
|
|
236
|
+
</FieldLabel>
|
|
237
|
+
<Input name="confirm" onChange={handleChange} type="text" />
|
|
238
|
+
</FieldRoot>
|
|
241
239
|
</VStack>
|
|
242
240
|
|
|
243
241
|
<HStack gap="md" justify="stretch" w="full">
|
package/src/hooks/useDate.ts
CHANGED
|
@@ -38,13 +38,7 @@ export interface UseDateReturn extends UseDateBase {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* const MyComponent = () => {
|
|
45
|
-
* const date = useDate({ initialValue: '01 JAN 2024' })
|
|
46
|
-
* return <input onChange={date.onChange} type="text" value={date.value} />
|
|
47
|
-
* }
|
|
41
|
+
* @deprecated use the DatePicker family instead
|
|
48
42
|
*/
|
|
49
43
|
export function useDate(options?: UseDateOptions): UseDateReturn {
|
|
50
44
|
const initialValue = options?.initialValue ?? ''
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
// deprecated
|
|
7
7
|
|
|
8
|
+
export * from './components/deprecated/FieldMessage'
|
|
9
|
+
export * from './components/deprecated/Label'
|
|
8
10
|
export * from './components/deprecated/Modal'
|
|
9
11
|
export * from './components/deprecated/ModalHeader'
|
|
10
12
|
export * from './components/deprecated/ModalHeading'
|
|
@@ -12,6 +14,7 @@ export * from './components/deprecated/ModalDescription'
|
|
|
12
14
|
export * from './components/deprecated/NavMenuTrigger'
|
|
13
15
|
export * from './components/deprecated/NavMenuList'
|
|
14
16
|
export * from './components/deprecated/NavMenuLink'
|
|
17
|
+
export * from './hooks/useDate'
|
|
15
18
|
|
|
16
19
|
// components
|
|
17
20
|
|
|
@@ -28,15 +31,13 @@ export * from './components/DatePicker.server'
|
|
|
28
31
|
export * from './components/Dialog'
|
|
29
32
|
export * from './components/Dialog.client'
|
|
30
33
|
export * from './components/Droppable'
|
|
31
|
-
export * from './components/FieldMessage'
|
|
32
34
|
export * from './components/FeatureFlag'
|
|
35
|
+
export * from './components/field/index'
|
|
33
36
|
export * from './components/Fieldset'
|
|
34
37
|
export * from './components/FieldsetLabel'
|
|
35
38
|
export * from './components/FileStatus'
|
|
36
39
|
export * from './components/FileUploader'
|
|
37
40
|
export * from './components/IconButton'
|
|
38
|
-
export * from './components/Input'
|
|
39
|
-
export * from './components/Label'
|
|
40
41
|
export * from './components/Legend'
|
|
41
42
|
export * from './components/Menu'
|
|
42
43
|
export * from './components/Notification'
|
|
@@ -54,7 +55,6 @@ export * from './components/Td'
|
|
|
54
55
|
export * from './components/Tbody'
|
|
55
56
|
export * from './components/Tag'
|
|
56
57
|
export * from './components/Text'
|
|
57
|
-
export * from './components/Textarea'
|
|
58
58
|
export * from './components/Toggle'
|
|
59
59
|
export * from './components/Tooltip'
|
|
60
60
|
export * from './components/Select'
|
|
@@ -67,7 +67,6 @@ export * from './context/cerberus'
|
|
|
67
67
|
export * from './context/confirm-modal'
|
|
68
68
|
export * from './context/cta-modal'
|
|
69
69
|
export * from './context/feature-flags'
|
|
70
|
-
export * from './context/field'
|
|
71
70
|
export * from './context/navMenu'
|
|
72
71
|
export * from './context/notification-center'
|
|
73
72
|
export * from './context/prompt-modal'
|
|
@@ -76,7 +75,6 @@ export * from './context/theme'
|
|
|
76
75
|
|
|
77
76
|
// hooks
|
|
78
77
|
|
|
79
|
-
export * from './hooks/useDate'
|
|
80
78
|
export * from './hooks/useModal'
|
|
81
79
|
export * from './hooks/useTheme'
|
|
82
80
|
export * from './hooks/useToggle'
|
package/src/utils/index.ts
CHANGED
|
@@ -18,4 +18,34 @@ export function formatNotifyCount(count: number): string {
|
|
|
18
18
|
return count.toString()
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Splits the properties of an object into multiple groups based on lists of keys.
|
|
23
|
+
* @param props - The object to split.
|
|
24
|
+
* @param keyGroups - The lists of keys to include in each group.
|
|
25
|
+
* @returns An array of objects: each containing the properties specified in the corresponding key group, and the last object containing the remaining keys.
|
|
26
|
+
*/
|
|
27
|
+
export function splitProps<T extends object>(
|
|
28
|
+
props: T,
|
|
29
|
+
...keyGroups: (keyof T)[][]
|
|
30
|
+
): { [K in keyof T]?: T[K] }[] {
|
|
31
|
+
const result = keyGroups.map(() => ({}) as { [K in keyof T]?: T[K] })
|
|
32
|
+
const rest = {} as { [K in keyof T]?: T[K] }
|
|
33
|
+
|
|
34
|
+
for (const key in props) {
|
|
35
|
+
let assigned = false
|
|
36
|
+
for (let i = 0; i < keyGroups.length; i++) {
|
|
37
|
+
if (keyGroups[i].includes(key as keyof T)) {
|
|
38
|
+
result[i][key as keyof T] = props[key]
|
|
39
|
+
assigned = true
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!assigned) {
|
|
44
|
+
rest[key as keyof T] = props[key]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [...result, rest]
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
export * from './localStorage'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FieldMessage.tsx","../../../src/context/field.tsx"],"sourcesContent":["'use client'\n\nimport type { HTMLAttributes } from 'react'\nimport { cx } from '@cerberus/styled-system/css'\nimport {\n fieldMessage,\n type FieldMessageVariantProps,\n} from '@cerberus/styled-system/recipes'\nimport { useFieldContext } from '../context/field'\n\n/**\n * This module contains the FieldMessage component.\n * @module\n */\nexport interface FieldMessageBaseProps\n extends HTMLAttributes<HTMLParagraphElement> {\n /**\n * The id of the FieldMessage element describing the field. Required for accessibility. It is considered best practice to use the `help` or `error` prefix to help screen readers identify the type of message.\n *\n * @example For help messages: `help:field_id`\n * @example For error messages: `error:field_id`\n */\n id: string\n}\nexport type FieldMessageProps = FieldMessageBaseProps & FieldMessageVariantProps\n\n/**\n * A component that provides feedback about the field.\n * @see https://cerberus.digitalu.design/react/field-message\n * @example\n * ```tsx\n * <Field>\n * <Label htmlFor=\"first_name\">First Name</Label>\n * <Input aria-describedBy=\"help:first_name\" id=\"first_name\" type=\"text\" />\n * <FieldMessage id=\"help:first_name\">\n * This will only be used in your account information.\n * </FieldMessage>\n * </Field>\n * ```\n */\nexport function FieldMessage(props: FieldMessageProps) {\n const { invalid } = useFieldContext()\n return (\n <small\n {...props}\n {...(invalid && { 'aria-invalid': true })}\n className={cx(props.className, fieldMessage())}\n />\n )\n}\n","'use client'\n\nimport {\n createContext,\n useContext,\n useMemo,\n type PropsWithChildren,\n} from 'react'\n\n/**\n * This module provides a context and hook for the field.\n * @module Field\n */\n\nexport interface FieldContextValue {\n /**\n * Whether the field is disabled.\n * @description [Moz Input Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes)\n */\n disabled?: boolean\n /**\n * Whether the field is read-only.\n */\n readOnly?: boolean\n /**\n * Whether the field is required.\n */\n required?: boolean\n /**\n * Whether the field is invalid.\n */\n invalid?: boolean\n}\n\nconst FieldContext = createContext<FieldContextValue | null>(null)\n\n/**\n * Provides the field state for a all related components used within a group.\n * @see https://cerberus.digitalu.design/react/input\n */\nexport function Field(\n props: PropsWithChildren<FieldContextValue>,\n): JSX.Element {\n const value = useMemo(\n () => ({\n disabled: props.disabled,\n readOnly: props.readOnly,\n required: props.required,\n invalid: props.invalid,\n }),\n [props.disabled, props.readOnly, props.required, props.invalid],\n )\n\n return (\n <FieldContext.Provider value={value}>\n {props.children}\n </FieldContext.Provider>\n )\n}\n\n/**\n * Used to access the field context.\n * @returns The field context.\n */\nexport function useFieldContext(): FieldContextValue {\n const context = useContext(FieldContext)\n if (!context) {\n throw new Error('useFieldContext must be used within a Field Provider.')\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAmB;AACnB,qBAGO;;;ACLP,mBAKO;AA+CH;AApBJ,IAAM,mBAAe,4BAAwC,IAAI;AA8B1D,SAAS,kBAAqC;AACnD,QAAM,cAAU,yBAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,SAAO;AACT;;;AD3BI,IAAAA,sBAAA;AAHG,SAAS,aAAa,OAA0B;AACrD,QAAM,EAAE,QAAQ,IAAI,gBAAgB;AACpC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAI,WAAW,EAAE,gBAAgB,KAAK;AAAA,MACvC,eAAW,eAAG,MAAM,eAAW,6BAAa,CAAC;AAAA;AAAA,EAC/C;AAEJ;","names":["import_jsx_runtime"]}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/components/Input.tsx
|
|
22
|
-
var Input_exports = {};
|
|
23
|
-
__export(Input_exports, {
|
|
24
|
-
Input: () => Input
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(Input_exports);
|
|
27
|
-
var import_recipes = require("@cerberus/styled-system/recipes");
|
|
28
|
-
var import_css = require("@cerberus/styled-system/css");
|
|
29
|
-
|
|
30
|
-
// src/context/field.tsx
|
|
31
|
-
var import_react = require("react");
|
|
32
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var FieldContext = (0, import_react.createContext)(null);
|
|
34
|
-
function useFieldContext() {
|
|
35
|
-
const context = (0, import_react.useContext)(FieldContext);
|
|
36
|
-
if (!context) {
|
|
37
|
-
throw new Error("useFieldContext must be used within a Field Provider.");
|
|
38
|
-
}
|
|
39
|
-
return context;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/context/cerberus.tsx
|
|
43
|
-
var import_react2 = require("react");
|
|
44
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
45
|
-
var CerberusContext = (0, import_react2.createContext)(null);
|
|
46
|
-
function useCerberusContext() {
|
|
47
|
-
const context = (0, import_react2.useContext)(CerberusContext);
|
|
48
|
-
if (!context) {
|
|
49
|
-
throw new Error("useCerberus must be used within a CerberusProvider");
|
|
50
|
-
}
|
|
51
|
-
return context;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// src/components/Show.tsx
|
|
55
|
-
var import_react3 = require("react");
|
|
56
|
-
function Show(props) {
|
|
57
|
-
const { when, children, fallback } = props;
|
|
58
|
-
const condition = (0, import_react3.useMemo)(() => when ?? false, [when]);
|
|
59
|
-
return (0, import_react3.useMemo)(() => {
|
|
60
|
-
if (condition) return children;
|
|
61
|
-
return fallback ?? null;
|
|
62
|
-
}, [condition, children, fallback]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/components/Input.tsx
|
|
66
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
67
|
-
function Input(props) {
|
|
68
|
-
const { describedBy, size, startIcon, endIcon, ...nativeProps } = props;
|
|
69
|
-
const inputStyles = (0, import_recipes.input)({ size });
|
|
70
|
-
const { invalid, ...fieldStates } = useFieldContext();
|
|
71
|
-
const hasEndIcon = Boolean(endIcon);
|
|
72
|
-
const { icons } = useCerberusContext();
|
|
73
|
-
const { invalid: InvalidIcon } = icons;
|
|
74
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: inputStyles.root, children: [
|
|
75
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Show, { when: Boolean(startIcon), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: inputStyles.startIcon, children: startIcon }) }),
|
|
76
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
77
|
-
"input",
|
|
78
|
-
{
|
|
79
|
-
...nativeProps,
|
|
80
|
-
...fieldStates,
|
|
81
|
-
...describedBy && { "aria-describedby": describedBy },
|
|
82
|
-
...invalid && { "aria-invalid": true },
|
|
83
|
-
"data-start-icon": Boolean(startIcon),
|
|
84
|
-
className: (0, import_css.cx)("peer", nativeProps.className, inputStyles.input)
|
|
85
|
-
}
|
|
86
|
-
),
|
|
87
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Show, { when: invalid, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(InvalidIcon, { className: inputStyles.icon }) }),
|
|
88
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Show, { when: hasEndIcon && !invalid, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: inputStyles.icon, children: endIcon }) })
|
|
89
|
-
] });
|
|
90
|
-
}
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
Input
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=Input.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Input.tsx","../../../src/context/field.tsx","../../../src/context/cerberus.tsx","../../../src/components/Show.tsx"],"sourcesContent":["'use client'\n\nimport type { InputHTMLAttributes, ReactNode } from 'react'\nimport { input, type InputVariantProps } from '@cerberus/styled-system/recipes'\nimport { cx } from '@cerberus/styled-system/css'\nimport { useFieldContext } from '../context/field'\nimport { useCerberusContext } from '../context/cerberus'\nimport { Show } from './Show'\n\nexport interface InputBaseProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'size'> {\n /**\n * The id of the FieldMessage component used to describe the input. Required for accessibility.\n */\n describedBy?: string\n /**\n * The unique identifier for the input element. Required for accessibility.\n */\n id: string\n /**\n * An optional icon to display at the start of the input.\n */\n startIcon?: ReactNode\n /**\n * An optional icon to display at the end of the input.\n */\n endIcon?: ReactNode\n}\nexport type InputProps = InputBaseProps & InputVariantProps\n\n/**\n * A component that allows the user to input text. Must be wrapped in a Field\n * component to keep track of the state for entire group of elements related to\n * the field.\n * @see https://cerberus.digitalu.design/react/input\n */\nexport function Input(props: InputProps) {\n const { describedBy, size, startIcon, endIcon, ...nativeProps } = props\n const inputStyles = input({ size })\n const { invalid, ...fieldStates } = useFieldContext()\n const hasEndIcon = Boolean(endIcon)\n\n const { icons } = useCerberusContext()\n const { invalid: InvalidIcon } = icons\n\n return (\n <div className={inputStyles.root}>\n <Show when={Boolean(startIcon)}>\n <span className={inputStyles.startIcon}>{startIcon}</span>\n </Show>\n\n <input\n {...nativeProps}\n {...fieldStates}\n {...(describedBy && { 'aria-describedby': describedBy })}\n {...(invalid && { 'aria-invalid': true })}\n data-start-icon={Boolean(startIcon)}\n className={cx('peer', nativeProps.className, inputStyles.input)}\n />\n\n <Show when={invalid}>\n <InvalidIcon className={inputStyles.icon} />\n </Show>\n <Show when={hasEndIcon && !invalid}>\n <span className={inputStyles.icon}>{endIcon}</span>\n </Show>\n </div>\n )\n}\n","'use client'\n\nimport {\n createContext,\n useContext,\n useMemo,\n type PropsWithChildren,\n} from 'react'\n\n/**\n * This module provides a context and hook for the field.\n * @module Field\n */\n\nexport interface FieldContextValue {\n /**\n * Whether the field is disabled.\n * @description [Moz Input Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes)\n */\n disabled?: boolean\n /**\n * Whether the field is read-only.\n */\n readOnly?: boolean\n /**\n * Whether the field is required.\n */\n required?: boolean\n /**\n * Whether the field is invalid.\n */\n invalid?: boolean\n}\n\nconst FieldContext = createContext<FieldContextValue | null>(null)\n\n/**\n * Provides the field state for a all related components used within a group.\n * @see https://cerberus.digitalu.design/react/input\n */\nexport function Field(\n props: PropsWithChildren<FieldContextValue>,\n): JSX.Element {\n const value = useMemo(\n () => ({\n disabled: props.disabled,\n readOnly: props.readOnly,\n required: props.required,\n invalid: props.invalid,\n }),\n [props.disabled, props.readOnly, props.required, props.invalid],\n )\n\n return (\n <FieldContext.Provider value={value}>\n {props.children}\n </FieldContext.Provider>\n )\n}\n\n/**\n * Used to access the field context.\n * @returns The field context.\n */\nexport function useFieldContext(): FieldContextValue {\n const context = useContext(FieldContext)\n if (!context) {\n throw new Error('useFieldContext must be used within a Field Provider.')\n }\n return context\n}\n","'use client'\n\nimport { createContext, useContext, type PropsWithChildren } from 'react'\nimport type { SystemConfig } from '../config'\n\n/**\n * This module contains the Cerberus configuration context and helpers.\n * @module context/cerberus\n */\n\ntype CerberusContextValue = SystemConfig\n\nconst CerberusContext = createContext<CerberusContextValue | null>(null)\n\ninterface CerberusProviderProps {\n config: SystemConfig\n}\n\n/**\n * Cerberus configuration provider.\n * @param props.config The Cerberus configuration created with\n * `makeSystemConfig` helper.\n */\nexport function CerberusProvider(\n props: PropsWithChildren<CerberusProviderProps>,\n) {\n return (\n <CerberusContext.Provider value={props.config}>\n {props.children}\n </CerberusContext.Provider>\n )\n}\n\n/**\n * Returns the Cerberus configuration context.\n * @returns The Cerberus configuration context.\n */\nexport function useCerberusContext() {\n const context = useContext(CerberusContext)\n if (!context) {\n throw new Error('useCerberus must be used within a CerberusProvider')\n }\n return context\n}\n","'use client'\n\nimport { useMemo, type PropsWithChildren, type ReactNode } from 'react'\n\n/**\n * This module contains the Show component.\n * @module\n */\n\nexport interface ShowProps {\n /**\n * The condition to render memoized children or the fallback content.\n */\n when: boolean | null | undefined\n /**\n * The children to render when the condition is false.\n */\n fallback?: ReactNode\n}\n\n/**\n * Conditionally render a memoized version of the children or optional fallback\n * content.\n * @see https://cerberus.digitalu.design/react/show\n * @example\n * ```tsx\n * <Show when={isLoggedIn} fallback={<Navigate to=\"/login\" />}>\n * <Dashboard />\n * </Show>\n */\nexport function Show(props: PropsWithChildren<ShowProps>): ReactNode {\n const { when, children, fallback } = props\n const condition = useMemo(() => when ?? false, [when])\n\n return useMemo(() => {\n if (condition) return children\n return fallback ?? null\n }, [condition, children, fallback])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8C;AAC9C,iBAAmB;;;ACFnB,mBAKO;AA+CH;AApBJ,IAAM,mBAAe,4BAAwC,IAAI;AA8B1D,SAAS,kBAAqC;AACnD,QAAM,cAAU,yBAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,SAAO;AACT;;;ACpEA,IAAAA,gBAAkE;AAyB9D,IAAAC,sBAAA;AAfJ,IAAM,sBAAkB,6BAA2C,IAAI;AAyBhE,SAAS,qBAAqB;AACnC,QAAM,cAAU,0BAAW,eAAe;AAC1C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;ACzCA,IAAAC,gBAAgE;AA4BzD,SAAS,KAAK,OAAgD;AACnE,QAAM,EAAE,MAAM,UAAU,SAAS,IAAI;AACrC,QAAM,gBAAY,uBAAQ,MAAM,QAAQ,OAAO,CAAC,IAAI,CAAC;AAErD,aAAO,uBAAQ,MAAM;AACnB,QAAI,UAAW,QAAO;AACtB,WAAO,YAAY;AAAA,EACrB,GAAG,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;;;AHQI,IAAAC,sBAAA;AAVG,SAAS,MAAM,OAAmB;AACvC,QAAM,EAAE,aAAa,MAAM,WAAW,SAAS,GAAG,YAAY,IAAI;AAClE,QAAM,kBAAc,sBAAM,EAAE,KAAK,CAAC;AAClC,QAAM,EAAE,SAAS,GAAG,YAAY,IAAI,gBAAgB;AACpD,QAAM,aAAa,QAAQ,OAAO;AAElC,QAAM,EAAE,MAAM,IAAI,mBAAmB;AACrC,QAAM,EAAE,SAAS,YAAY,IAAI;AAEjC,SACE,8CAAC,SAAI,WAAW,YAAY,MAC1B;AAAA,iDAAC,QAAK,MAAM,QAAQ,SAAS,GAC3B,uDAAC,UAAK,WAAW,YAAY,WAAY,qBAAU,GACrD;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACH,GAAG;AAAA,QACH,GAAI,eAAe,EAAE,oBAAoB,YAAY;AAAA,QACrD,GAAI,WAAW,EAAE,gBAAgB,KAAK;AAAA,QACvC,mBAAiB,QAAQ,SAAS;AAAA,QAClC,eAAW,eAAG,QAAQ,YAAY,WAAW,YAAY,KAAK;AAAA;AAAA,IAChE;AAAA,IAEA,6CAAC,QAAK,MAAM,SACV,uDAAC,eAAY,WAAW,YAAY,MAAM,GAC5C;AAAA,IACA,6CAAC,QAAK,MAAM,cAAc,CAAC,SACzB,uDAAC,UAAK,WAAW,YAAY,MAAO,mBAAQ,GAC9C;AAAA,KACF;AAEJ;","names":["import_react","import_jsx_runtime","import_react","import_jsx_runtime"]}
|