@sakura-ui/sakura-ui 0.2.0 → 0.3.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.
- package/README.md +16 -6
- package/package.json +21 -15
- package/packages/core/package.json +26 -15
- package/packages/core/src/components/Button.tsx +33 -32
- package/packages/core/src/components/Card.tsx +29 -17
- package/packages/core/src/components/Code.tsx +6 -4
- package/packages/core/src/components/Faq.tsx +13 -7
- package/packages/core/src/components/Heading.tsx +42 -32
- package/packages/core/src/components/Icon.tsx +43 -13
- package/packages/core/src/components/IconButton.tsx +54 -43
- package/packages/core/src/components/LangSelector.tsx +135 -0
- package/packages/core/src/components/Link.tsx +38 -66
- package/packages/core/src/components/LinkCard.tsx +91 -0
- package/packages/core/src/components/List.tsx +14 -12
- package/packages/core/src/components/MenuButton.tsx +112 -0
- package/packages/core/src/components/NavigationItem.tsx +41 -0
- package/packages/core/src/components/OverflowContainer.tsx +24 -0
- package/packages/core/src/components/PopoverMenu.tsx +81 -0
- package/packages/core/src/components/Pre.tsx +6 -4
- package/packages/core/src/components/Table.tsx +31 -25
- package/packages/core/src/components/buttonStyle.ts +42 -31
- package/packages/core/src/components/index.ts +13 -25
- package/packages/core/src/icons/Close.tsx +21 -0
- package/packages/core/src/icons/CloseMobile.tsx +43 -0
- package/packages/core/src/icons/KeyboardArrowDown.tsx +24 -0
- package/packages/core/src/icons/Language.tsx +25 -0
- package/packages/core/src/icons/LanguageMobile.tsx +40 -0
- package/packages/core/src/icons/Menu.tsx +24 -0
- package/packages/core/src/icons/MenuMobile.tsx +40 -0
- package/packages/core/src/icons/index.ts +8 -0
- package/packages/core/src/icons/props.ts +5 -0
- package/packages/core/src/index.ts +9 -28
- package/packages/core/src/type.d.ts +1 -0
- package/packages/core/tests/Button.test.tsx +20 -10
- package/packages/core/tests/Card.test.tsx +16 -11
- package/packages/core/tests/IconButton.test.tsx +57 -0
- package/packages/core/tests/Link.test.tsx +60 -0
- package/packages/core/tests/vitest.setup.ts +1 -0
- package/packages/core/tsconfig.node.json +3 -2
- package/packages/forms/.turbo/turbo-build.log +22 -0
- package/packages/forms/dist/index.cjs.js +199 -120
- package/packages/forms/dist/index.es.js +890 -1023
- package/packages/forms/dist/types/components/Checkbox.d.ts +9 -4
- package/packages/forms/dist/types/components/Checkbox.d.ts.map +1 -1
- package/packages/forms/dist/types/components/FieldsetControl.d.ts +14 -9
- package/packages/forms/dist/types/components/FieldsetControl.d.ts.map +1 -1
- package/packages/forms/dist/types/components/FileInput.d.ts +10 -3
- package/packages/forms/dist/types/components/FileInput.d.ts.map +1 -1
- package/packages/forms/dist/types/components/Input.d.ts +9 -4
- package/packages/forms/dist/types/components/Input.d.ts.map +1 -1
- package/packages/forms/dist/types/components/LabelControl.d.ts +13 -8
- package/packages/forms/dist/types/components/LabelControl.d.ts.map +1 -1
- package/packages/forms/dist/types/components/Radio.d.ts +9 -4
- package/packages/forms/dist/types/components/Radio.d.ts.map +1 -1
- package/packages/forms/dist/types/components/Select.d.ts +9 -4
- package/packages/forms/dist/types/components/Select.d.ts.map +1 -1
- package/packages/forms/dist/types/components/Textarea.d.ts +8 -3
- package/packages/forms/dist/types/components/Textarea.d.ts.map +1 -1
- package/packages/forms/dist/types/components/controlled/CheckboxGroup.d.ts +16 -11
- package/packages/forms/dist/types/components/controlled/CheckboxGroup.d.ts.map +1 -1
- package/packages/forms/dist/types/components/controlled/RadioGroup.d.ts +17 -12
- package/packages/forms/dist/types/components/controlled/RadioGroup.d.ts.map +1 -1
- package/packages/forms/dist/types/components/index.d.ts +8 -8
- package/packages/forms/dist/types/components/index.d.ts.map +1 -1
- package/packages/forms/dist/types/components/inputStyle.d.ts +1 -1
- package/packages/forms/dist/types/components/inputStyle.d.ts.map +1 -1
- package/packages/forms/dist/types/index.d.ts +0 -1
- package/packages/forms/dist/types/index.d.ts.map +1 -1
- package/packages/forms/node_modules/.bin/autoprefixer +2 -2
- package/packages/forms/node_modules/.bin/tailwind +2 -2
- package/packages/forms/node_modules/.bin/tailwindcss +2 -2
- package/packages/forms/node_modules/.bin/ts-node +4 -4
- package/packages/forms/node_modules/.bin/ts-node-cwd +4 -4
- package/packages/forms/node_modules/.bin/ts-node-esm +4 -4
- package/packages/forms/node_modules/.bin/ts-node-script +4 -4
- package/packages/forms/node_modules/.bin/ts-node-transpile-only +4 -4
- package/packages/forms/node_modules/.bin/ts-script +4 -4
- package/packages/forms/node_modules/.bin/tsc +17 -0
- package/packages/forms/node_modules/.bin/tsserver +17 -0
- package/packages/forms/node_modules/.vite/vitest/results.json +1 -0
- package/packages/forms/package.json +17 -14
- package/packages/forms/src/components/Checkbox.tsx +76 -80
- package/packages/forms/src/components/FieldsetControl.tsx +21 -28
- package/packages/forms/src/components/FileInput.tsx +87 -63
- package/packages/forms/src/components/Input.tsx +29 -31
- package/packages/forms/src/components/LabelControl.tsx +19 -25
- package/packages/forms/src/components/Radio.tsx +66 -69
- package/packages/forms/src/components/Select.tsx +65 -65
- package/packages/forms/src/components/Textarea.tsx +49 -54
- package/packages/forms/src/components/controlled/CheckboxGroup.tsx +15 -17
- package/packages/forms/src/components/controlled/RadioGroup.tsx +16 -18
- package/packages/forms/src/components/index.ts +8 -8
- package/packages/forms/src/components/inputStyle.ts +7 -8
- package/packages/forms/src/index.ts +0 -11
- package/packages/forms/tests/Checkbox.test.tsx +44 -0
- package/packages/forms/tests/FieldsetControl.test.tsx +62 -11
- package/packages/forms/tests/FileInput.test.tsx +25 -0
- package/packages/forms/tests/Input.test.tsx +12 -83
- package/packages/forms/tests/LabelControl.test.tsx +82 -20
- package/packages/forms/tests/Radio.test.tsx +23 -78
- package/packages/forms/tests/Select.test.tsx +30 -0
- package/packages/forms/tests/Textarea.test.tsx +25 -0
- package/packages/forms/tests/vitest.setup.ts +1 -0
- package/packages/forms/tsconfig.node.json +3 -2
- package/packages/helper/.turbo/turbo-build.log +23 -0
- package/packages/helper/dist/index.cjs.js +78 -0
- package/packages/helper/dist/index.es.js +119 -0
- package/packages/helper/dist/types/calc.d.ts +2 -0
- package/packages/helper/dist/types/calc.d.ts.map +1 -0
- package/packages/{forms/dist/types/utils/class.d.ts → helper/dist/types/cx.d.ts} +1 -1
- package/packages/helper/dist/types/cx.d.ts.map +1 -0
- package/packages/helper/dist/types/index.d.ts +6 -0
- package/packages/helper/dist/types/index.d.ts.map +1 -0
- package/packages/helper/dist/types/querySelector.d.ts +2 -0
- package/packages/helper/dist/types/querySelector.d.ts.map +1 -0
- package/packages/helper/dist/types/styles.d.ts +22 -0
- package/packages/helper/dist/types/styles.d.ts.map +1 -0
- package/packages/helper/dist/types/treefy.d.ts +8 -0
- package/packages/helper/dist/types/treefy.d.ts.map +1 -0
- package/packages/helper/package.json +40 -0
- package/packages/helper/src/calc.ts +1 -0
- package/packages/helper/src/index.ts +5 -0
- package/packages/helper/src/querySelector.ts +20 -0
- package/packages/helper/src/styles.ts +116 -0
- package/packages/helper/src/treefy.ts +22 -0
- package/packages/helper/tsconfig.json +13 -0
- package/packages/helper/tsconfig.node.json +6 -0
- package/packages/helper/vite.config.ts +26 -0
- package/packages/markdown/.turbo/turbo-build.log +22 -0
- package/packages/markdown/README.md +129 -0
- package/packages/markdown/dist/index.cjs.js +175 -0
- package/packages/markdown/dist/index.es.js +17098 -0
- package/packages/markdown/dist/types/components/Markdown.d.ts +15 -0
- package/packages/markdown/dist/types/components/Markdown.d.ts.map +1 -0
- package/packages/markdown/dist/types/components/index.d.ts +2 -0
- package/packages/markdown/dist/types/components/index.d.ts.map +1 -0
- package/packages/markdown/dist/types/index.d.ts +2 -0
- package/packages/markdown/dist/types/index.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/attr.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/attr.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/card.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/card.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/cell.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/cell.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/faq.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/faq.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/grid.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/grid.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/headings.d.ts +9 -0
- package/packages/markdown/dist/types/plugins/headings.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/helper.d.ts +9 -0
- package/packages/markdown/dist/types/plugins/helper.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/index.d.ts +9 -0
- package/packages/markdown/dist/types/plugins/index.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/linkButton.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/linkButton.d.ts.map +1 -0
- package/packages/markdown/dist/types/plugins/youtube.d.ts +3 -0
- package/packages/markdown/dist/types/plugins/youtube.d.ts.map +1 -0
- package/packages/markdown/node_modules/.bin/autoprefixer +17 -0
- package/packages/markdown/node_modules/.bin/tailwind +17 -0
- package/packages/markdown/node_modules/.bin/tailwindcss +17 -0
- package/packages/markdown/node_modules/.bin/ts-node +17 -0
- package/packages/markdown/node_modules/.bin/ts-node-cwd +17 -0
- package/packages/markdown/node_modules/.bin/ts-node-esm +17 -0
- package/packages/markdown/node_modules/.bin/ts-node-script +17 -0
- package/packages/markdown/node_modules/.bin/ts-node-transpile-only +17 -0
- package/packages/markdown/node_modules/.bin/ts-script +17 -0
- package/packages/markdown/node_modules/.bin/tsc +17 -0
- package/packages/markdown/node_modules/.bin/tsserver +17 -0
- package/packages/markdown/package.json +83 -0
- package/packages/markdown/src/components/Markdown.tsx +361 -0
- package/packages/markdown/src/components/index.ts +1 -0
- package/packages/markdown/src/global.d.ts +9 -0
- package/packages/markdown/src/index.ts +1 -0
- package/packages/markdown/src/plugins/attr.ts +19 -0
- package/packages/markdown/src/plugins/card.ts +57 -0
- package/packages/markdown/src/plugins/cell.ts +47 -0
- package/packages/markdown/src/plugins/faq.ts +40 -0
- package/packages/markdown/src/plugins/grid.ts +51 -0
- package/packages/markdown/src/plugins/headings.ts +35 -0
- package/packages/markdown/src/plugins/helper.ts +27 -0
- package/packages/markdown/src/plugins/index.ts +8 -0
- package/packages/markdown/src/plugins/linkButton.ts +25 -0
- package/packages/markdown/src/plugins/youtube.ts +48 -0
- package/packages/markdown/tsconfig.json +13 -0
- package/packages/markdown/tsconfig.node.json +7 -0
- package/packages/markdown/vite.config.ts +30 -0
- package/packages/tailwind-theme-plugin/.turbo/turbo-build.log +22 -0
- package/packages/tailwind-theme-plugin/dist/index.cjs.js +1 -1
- package/packages/tailwind-theme-plugin/dist/index.es.js +5354 -6111
- package/packages/tailwind-theme-plugin/dist/types/index.d.ts +1 -1
- package/packages/tailwind-theme-plugin/dist/types/index.d.ts.map +1 -1
- package/packages/tailwind-theme-plugin/node_modules/.bin/autoprefixer +2 -2
- package/packages/tailwind-theme-plugin/node_modules/.bin/tailwind +2 -2
- package/packages/tailwind-theme-plugin/node_modules/.bin/tailwindcss +2 -2
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-node +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-node-cwd +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-node-esm +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-node-script +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-node-transpile-only +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/ts-script +4 -4
- package/packages/tailwind-theme-plugin/node_modules/.bin/tsc +17 -0
- package/packages/tailwind-theme-plugin/node_modules/.bin/tsserver +17 -0
- package/packages/tailwind-theme-plugin/package.json +6 -6
- package/packages/tailwind-theme-plugin/src/index.ts +226 -291
- package/packages/core/src/libs/forward-ref.ts +0 -44
- package/packages/core/src/types/component.ts +0 -83
- package/packages/forms/dist/types/utils/class.d.ts.map +0 -1
- package/packages/forms/node_modules/.bin/acorn +0 -17
- package/packages/forms/node_modules/.bin/browserslist +0 -17
- package/packages/forms/node_modules/.bin/eslint +0 -17
- package/packages/forms/node_modules/.bin/vitest +0 -17
- package/packages/forms/src/utils/class.ts +0 -2
- package/packages/tailwind-theme-plugin/node_modules/.bin/browserslist +0 -17
- /package/packages/{core/src/libs → helper/src}/cx.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { cx } from '
|
|
1
|
+
import React, { type ComponentPropsWithRef } from 'react'
|
|
2
|
+
import { cx, Style } from '@sakura-ui/helper'
|
|
3
3
|
import { ControllerContext } from './context'
|
|
4
4
|
import {
|
|
5
5
|
type InputSize,
|
|
@@ -8,78 +8,75 @@ import {
|
|
|
8
8
|
iconStyles
|
|
9
9
|
} from './inputStyle'
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
extends Omit<
|
|
13
|
-
|
|
11
|
+
export namespace Radio {
|
|
12
|
+
export interface Props extends Omit<ComponentPropsWithRef<'input'>, 'size'> {
|
|
13
|
+
size?: InputSize
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export const Radio =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const styleInput = `
|
|
29
|
-
peer
|
|
30
|
-
sr-only
|
|
31
|
-
`
|
|
17
|
+
export const Radio = (props: Radio.Props) => {
|
|
18
|
+
const { id, className, size = 'lg', children, ...restProps } = props
|
|
19
|
+
const genId = React.useId()
|
|
20
|
+
const radioId = id || genId
|
|
21
|
+
const ctx = React.useContext(ControllerContext)
|
|
22
|
+
if (ctx.isRequired) {
|
|
23
|
+
restProps.required = true
|
|
24
|
+
}
|
|
25
|
+
if (ctx.groupName) {
|
|
26
|
+
restProps.name = ctx.groupName
|
|
27
|
+
}
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
border-solid
|
|
38
|
-
border-sumi-900
|
|
39
|
-
peer-checked:bg-sea-600
|
|
40
|
-
peer-checked:border-sea-600
|
|
41
|
-
peer-disabled:border-sumi-500
|
|
42
|
-
peer-focus-visible:ring-2
|
|
43
|
-
peer-focus-visible:ring-offset-2
|
|
44
|
-
peer-focus-visible:ring-wood-500
|
|
45
|
-
`
|
|
29
|
+
const styleInput = `
|
|
30
|
+
peer
|
|
31
|
+
sr-only
|
|
32
|
+
`
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
const styleRadio = `
|
|
35
|
+
bg-clip-content
|
|
36
|
+
rounded-full
|
|
37
|
+
border
|
|
38
|
+
border-solid
|
|
39
|
+
border-solid-gray-900
|
|
40
|
+
peer-checked:bg-blue-600
|
|
41
|
+
peer-checked:border-blue-600
|
|
42
|
+
peer-disabled:border-solid-gray-500
|
|
43
|
+
${Style.Peer.focusRect}
|
|
44
|
+
`
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
borderlessInputBaseStyles,
|
|
58
|
-
borderlessInputSizeStyles[size],
|
|
59
|
-
className
|
|
60
|
-
)}
|
|
61
|
-
>
|
|
62
|
-
<span className="flex items-center">
|
|
63
|
-
<input
|
|
64
|
-
id={radioId}
|
|
65
|
-
className={styleInput}
|
|
66
|
-
type="radio"
|
|
67
|
-
aria-describedby={ctx.helperTextId}
|
|
68
|
-
aria-errormessage={ctx.errorMessageId}
|
|
69
|
-
aria-invalid={ctx.isInvalid ?? false}
|
|
70
|
-
aria-required={ctx.isRequired ?? false}
|
|
71
|
-
{...restProps}
|
|
72
|
-
ref={ref}
|
|
73
|
-
/>
|
|
74
|
-
<span
|
|
75
|
-
aria-hidden={true}
|
|
76
|
-
className={cx(styleRadio, radioSizes[size], iconStyles[size])}
|
|
77
|
-
/>
|
|
78
|
-
<span className="peer-disabled:text-sumi-500">{children}</span>
|
|
79
|
-
</span>
|
|
80
|
-
</label>
|
|
81
|
-
)
|
|
46
|
+
const radioSizes: { [key in InputSize]: string } = {
|
|
47
|
+
lg: 'p-1',
|
|
48
|
+
md: 'p-[3px]',
|
|
49
|
+
sm: 'p-[3px]'
|
|
82
50
|
}
|
|
83
|
-
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<label
|
|
54
|
+
htmlFor={radioId}
|
|
55
|
+
className={cx(
|
|
56
|
+
borderlessInputBaseStyles,
|
|
57
|
+
borderlessInputSizeStyles[size],
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
<span className="flex items-center">
|
|
62
|
+
<input
|
|
63
|
+
id={radioId}
|
|
64
|
+
className={styleInput}
|
|
65
|
+
type="radio"
|
|
66
|
+
aria-describedby={ctx.helperTextId}
|
|
67
|
+
aria-errormessage={ctx.errorMessageId}
|
|
68
|
+
aria-invalid={ctx.isInvalid ?? false}
|
|
69
|
+
aria-required={ctx.isRequired ?? false}
|
|
70
|
+
{...restProps}
|
|
71
|
+
/>
|
|
72
|
+
<span
|
|
73
|
+
aria-hidden={true}
|
|
74
|
+
className={cx(styleRadio, radioSizes[size], iconStyles[size])}
|
|
75
|
+
/>
|
|
76
|
+
<span className="peer-disabled:text-solid-gray-500">{children}</span>
|
|
77
|
+
</span>
|
|
78
|
+
</label>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
84
81
|
|
|
85
82
|
Radio.displayName = 'Radio'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { cx } from '
|
|
1
|
+
import React, { type ComponentPropsWithRef } from 'react'
|
|
2
|
+
import { cx } from '@sakura-ui/helper'
|
|
3
3
|
import { ControllerContext } from './context'
|
|
4
4
|
import {
|
|
5
5
|
type InputSize,
|
|
@@ -7,71 +7,71 @@ import {
|
|
|
7
7
|
borderedInputSizeStyles
|
|
8
8
|
} from './inputStyle'
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
extends Omit<
|
|
12
|
-
|
|
10
|
+
export namespace Select {
|
|
11
|
+
export interface Props extends Omit<ComponentPropsWithRef<'select'>, 'size'> {
|
|
12
|
+
size?: InputSize
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export const Select =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
16
|
+
export const Select = (props: Select.Props) => {
|
|
17
|
+
const { id, className, size = 'lg', children, ...restProps } = props
|
|
18
|
+
const ctx = React.useContext(ControllerContext)
|
|
19
|
+
if (ctx.isRequired) {
|
|
20
|
+
restProps.required = true
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const style = `
|
|
24
|
+
!pr-8
|
|
25
|
+
peer
|
|
26
|
+
cursor-pointer
|
|
27
|
+
appearance-none
|
|
28
|
+
`
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const styleArrow = `
|
|
31
|
+
pointer-events-none
|
|
32
|
+
absolute
|
|
33
|
+
right-4
|
|
34
|
+
top-1/2
|
|
35
|
+
-translate-y-1/2
|
|
36
|
+
text-solid-gray-900
|
|
37
|
+
peer-disabled:text-solid-gray-500
|
|
38
|
+
`
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
40
|
+
return (
|
|
41
|
+
<div className="inline-block relative">
|
|
42
|
+
<select
|
|
43
|
+
id={id || ctx.id}
|
|
44
|
+
className={cx(
|
|
45
|
+
style,
|
|
46
|
+
borderedInputBaseStyles,
|
|
47
|
+
borderedInputSizeStyles[size],
|
|
48
|
+
className
|
|
49
|
+
)}
|
|
50
|
+
aria-describedby={ctx.helperTextId}
|
|
51
|
+
aria-errormessage={ctx.errorMessageId}
|
|
52
|
+
aria-invalid={ctx.isInvalid ?? false}
|
|
53
|
+
aria-required={ctx.isRequired ?? false}
|
|
54
|
+
{...restProps}
|
|
55
|
+
>
|
|
56
|
+
{children}
|
|
57
|
+
</select>
|
|
58
|
+
<svg
|
|
59
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
60
|
+
aria-hidden={true}
|
|
61
|
+
className={styleArrow}
|
|
62
|
+
fill="none"
|
|
63
|
+
width="16"
|
|
64
|
+
height="16"
|
|
65
|
+
viewBox="0 0 16 16"
|
|
66
|
+
>
|
|
67
|
+
<title>arrow down</title>
|
|
68
|
+
<path
|
|
69
|
+
d="M12 15.05 6.35 9.4 7.4 8.35l4.6 4.6 4.6-4.6 1.05 1.05Z"
|
|
70
|
+
fill="currentColor"
|
|
71
|
+
/>
|
|
72
|
+
</svg>
|
|
73
|
+
</div>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Select.displayName = 'Select'
|
|
@@ -1,73 +1,68 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { cx } from '
|
|
1
|
+
import React, { type ComponentPropsWithRef } from 'react'
|
|
2
|
+
import { cx, Style } from '@sakura-ui/helper'
|
|
3
3
|
import { ControllerContext } from './context'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
extends
|
|
5
|
+
export namespace Textarea {
|
|
6
|
+
export interface Props extends ComponentPropsWithRef<'textarea'> {}
|
|
7
|
+
}
|
|
7
8
|
|
|
8
|
-
export const Textarea =
|
|
9
|
-
|
|
10
|
-
const { id, className, children, onChange, maxLength, ...restProps } = props
|
|
9
|
+
export const Textarea = (props: Textarea.Props) => {
|
|
10
|
+
const { id, className, children, onChange, maxLength, ...restProps } = props
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const [count, setCount] = React.useState(0)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const onChangeHandler = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
15
|
+
if (onChange) onChange(e)
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
setCount(e.target.value.length)
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const ctx = React.useContext(ControllerContext)
|
|
21
|
+
if (ctx.isRequired) {
|
|
22
|
+
restProps.required = true
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const overtextStyle =
|
|
26
|
+
count > (maxLength || 0) ? 'text-red-800' : 'text-solid-gray-700'
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const style = `
|
|
29
29
|
p-4
|
|
30
30
|
text-label
|
|
31
31
|
rounded-lg
|
|
32
32
|
border
|
|
33
33
|
border-solid
|
|
34
|
-
border-
|
|
35
|
-
outline-offset-2
|
|
36
|
-
focus:outline
|
|
37
|
-
focus:outline-2
|
|
38
|
-
focus:outline-wood-500
|
|
34
|
+
border-solid-gray-900
|
|
39
35
|
disabled:bg-transparent
|
|
40
|
-
disabled:text-
|
|
41
|
-
disabled:border-
|
|
42
|
-
aria-invalid:border-
|
|
36
|
+
disabled:text-solid-gray-500
|
|
37
|
+
disabled:border-solid-gray-500
|
|
38
|
+
aria-invalid:border-red-800
|
|
39
|
+
${Style.focusRect}
|
|
43
40
|
`
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
)
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<textarea
|
|
45
|
+
id={id || ctx.id}
|
|
46
|
+
className={cx(style, className)}
|
|
47
|
+
aria-describedby={ctx.helperTextId}
|
|
48
|
+
aria-errormessage={ctx.errorMessageId}
|
|
49
|
+
aria-invalid={ctx.isInvalid ?? false}
|
|
50
|
+
aria-required={ctx.isRequired ?? false}
|
|
51
|
+
onChange={onChangeHandler}
|
|
52
|
+
{...restProps}
|
|
53
|
+
>
|
|
54
|
+
{children}
|
|
55
|
+
</textarea>
|
|
56
|
+
{maxLength ? (
|
|
57
|
+
<p className="text-label text-solid-gray-700">
|
|
58
|
+
<span className={overtextStyle}>{count}</span>/
|
|
59
|
+
<span>{maxLength}</span>
|
|
60
|
+
</p>
|
|
61
|
+
) : (
|
|
62
|
+
''
|
|
63
|
+
)}
|
|
64
|
+
</>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
72
67
|
|
|
73
68
|
Textarea.displayName = 'Textarea'
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { type ComponentPropsWithRef } from 'react'
|
|
2
2
|
import { Checkbox } from '../Checkbox'
|
|
3
3
|
import { FieldsetControl } from '../FieldsetControl'
|
|
4
4
|
import type { InputItem } from './InputItem'
|
|
5
5
|
import type { InputSize } from '../inputStyle'
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export namespace CheckboxGroup {
|
|
8
|
+
export interface Props
|
|
9
|
+
extends Omit<ComponentPropsWithRef<'fieldset'>, 'onChange'> {
|
|
10
|
+
items: InputItem[]
|
|
11
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>
|
|
12
|
+
labelText: string
|
|
13
|
+
helperText?: string
|
|
14
|
+
errorMessage?: string
|
|
15
|
+
isInvalid?: boolean
|
|
16
|
+
isRequired?: boolean
|
|
17
|
+
size?: InputSize
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
export const CheckboxGroup =
|
|
20
|
-
HTMLFieldSetElement,
|
|
21
|
-
CheckboxGroupProps
|
|
22
|
-
>((props, ref) => {
|
|
21
|
+
export const CheckboxGroup = (props: CheckboxGroup.Props) => {
|
|
23
22
|
const {
|
|
24
23
|
items,
|
|
25
24
|
onChange,
|
|
@@ -41,7 +40,6 @@ export const CheckboxGroup = React.forwardRef<
|
|
|
41
40
|
errorMessage={errorMessage}
|
|
42
41
|
isInvalid={isInvalid}
|
|
43
42
|
isRequired={isRequired}
|
|
44
|
-
ref={ref}
|
|
45
43
|
{...restProps}
|
|
46
44
|
>
|
|
47
45
|
{items.map(({ label, value }) => {
|
|
@@ -58,6 +56,6 @@ export const CheckboxGroup = React.forwardRef<
|
|
|
58
56
|
})}
|
|
59
57
|
</FieldsetControl>
|
|
60
58
|
)
|
|
61
|
-
}
|
|
59
|
+
}
|
|
62
60
|
|
|
63
61
|
CheckboxGroup.displayName = 'CheckboxGroup'
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { type ComponentPropsWithRef } from 'react'
|
|
2
2
|
import { Radio } from '../Radio'
|
|
3
3
|
import { FieldsetControl } from '../FieldsetControl'
|
|
4
4
|
import type { InputItem } from './InputItem'
|
|
5
5
|
import type { InputSize } from '../inputStyle'
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export namespace RadioGroup {
|
|
8
|
+
export interface Props
|
|
9
|
+
extends Omit<ComponentPropsWithRef<'fieldset'>, 'onChange'> {
|
|
10
|
+
items: InputItem[]
|
|
11
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>
|
|
12
|
+
labelText: string
|
|
13
|
+
helperText?: string
|
|
14
|
+
errorMessage?: string
|
|
15
|
+
isInvalid?: boolean
|
|
16
|
+
isRequired?: boolean
|
|
17
|
+
defaultValue?: string
|
|
18
|
+
size?: InputSize
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export const RadioGroup =
|
|
21
|
-
HTMLFieldSetElement,
|
|
22
|
-
RadioGroupProps
|
|
23
|
-
>((props, ref) => {
|
|
22
|
+
export const RadioGroup = (props: RadioGroup.Props) => {
|
|
24
23
|
const {
|
|
25
24
|
items,
|
|
26
25
|
onChange,
|
|
@@ -43,7 +42,6 @@ export const RadioGroup = React.forwardRef<
|
|
|
43
42
|
errorMessage={errorMessage}
|
|
44
43
|
isInvalid={isInvalid}
|
|
45
44
|
isRequired={isRequired}
|
|
46
|
-
ref={ref}
|
|
47
45
|
{...restProps}
|
|
48
46
|
>
|
|
49
47
|
{items.map(({ label, value }) => {
|
|
@@ -61,6 +59,6 @@ export const RadioGroup = React.forwardRef<
|
|
|
61
59
|
})}
|
|
62
60
|
</FieldsetControl>
|
|
63
61
|
)
|
|
64
|
-
}
|
|
62
|
+
}
|
|
65
63
|
|
|
66
64
|
RadioGroup.displayName = 'RadioGroup'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { Checkbox
|
|
2
|
-
export { Radio
|
|
3
|
-
export { Select
|
|
4
|
-
export { FileInput
|
|
5
|
-
export { Input
|
|
6
|
-
export { Textarea
|
|
7
|
-
export { LabelControl
|
|
8
|
-
export { FieldsetControl
|
|
1
|
+
export { Checkbox } from './Checkbox'
|
|
2
|
+
export { Radio } from './Radio'
|
|
3
|
+
export { Select } from './Select'
|
|
4
|
+
export { FileInput } from './FileInput'
|
|
5
|
+
export { Input } from './Input'
|
|
6
|
+
export { Textarea } from './Textarea'
|
|
7
|
+
export { LabelControl } from './LabelControl'
|
|
8
|
+
export { FieldsetControl } from './FieldsetControl'
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import { Style } from '@sakura-ui/helper'
|
|
2
|
+
|
|
1
3
|
export type InputSize = 'lg' | 'md' | 'sm'
|
|
2
4
|
|
|
3
5
|
export const borderedInputBaseStyles = `
|
|
4
6
|
bg-white
|
|
5
7
|
border
|
|
6
8
|
border-solid
|
|
7
|
-
border-
|
|
8
|
-
outline-offset-2
|
|
9
|
-
focus:outline
|
|
10
|
-
focus:outline-2
|
|
11
|
-
focus:outline-wood-500
|
|
9
|
+
border-solid-gray-900
|
|
12
10
|
disabled:bg-transparent
|
|
13
|
-
disabled:text-
|
|
14
|
-
disabled:border-
|
|
15
|
-
aria-invalid:border-
|
|
11
|
+
disabled:text-solid-gray-500
|
|
12
|
+
disabled:border-solid-gray-500
|
|
13
|
+
aria-invalid:border-red-800
|
|
14
|
+
${Style.focusRect}
|
|
16
15
|
`
|
|
17
16
|
|
|
18
17
|
// for text input and select
|
|
@@ -9,15 +9,4 @@ export {
|
|
|
9
9
|
FieldsetControl
|
|
10
10
|
} from './components'
|
|
11
11
|
|
|
12
|
-
export type {
|
|
13
|
-
CheckboxProps,
|
|
14
|
-
RadioProps,
|
|
15
|
-
SelectProps,
|
|
16
|
-
FileInputProps,
|
|
17
|
-
InputProps,
|
|
18
|
-
TextareaProps,
|
|
19
|
-
LabelControlProps,
|
|
20
|
-
FieldsetControlProps
|
|
21
|
-
} from './components'
|
|
22
|
-
|
|
23
12
|
export { CheckboxGroup, RadioGroup } from './components/controlled'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
3
|
+
import { render, screen } from '@testing-library/react'
|
|
4
|
+
|
|
5
|
+
import { Checkbox } from '../src'
|
|
6
|
+
|
|
7
|
+
describe('Checkbox', () => {
|
|
8
|
+
it('should render a checkbox with a label text', async () => {
|
|
9
|
+
render(<Checkbox>test</Checkbox>)
|
|
10
|
+
|
|
11
|
+
const checkbox = screen.getByRole('checkbox')
|
|
12
|
+
|
|
13
|
+
expect(checkbox).toBeInTheDocument()
|
|
14
|
+
|
|
15
|
+
expect(screen.getByText('test')).toBeInTheDocument()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should render two checkbox with verify checked states', async () => {
|
|
19
|
+
render(
|
|
20
|
+
<>
|
|
21
|
+
<Checkbox id="test" value="test1" data-testid="checked" checked />
|
|
22
|
+
<Checkbox id="test" value="test2" data-testid="not_checked" />
|
|
23
|
+
</>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const checked = screen.getByTestId('checked')
|
|
27
|
+
|
|
28
|
+
expect(checked).toBeInTheDocument()
|
|
29
|
+
expect(checked).toBeChecked()
|
|
30
|
+
|
|
31
|
+
const notChecked = screen.getByTestId('not_checked')
|
|
32
|
+
|
|
33
|
+
expect(notChecked).toBeInTheDocument()
|
|
34
|
+
expect(notChecked).not.toBeChecked()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should pass an object to the ref property', async () => {
|
|
38
|
+
const ref = vi.fn()
|
|
39
|
+
|
|
40
|
+
render(<Checkbox ref={ref}>test</Checkbox>)
|
|
41
|
+
|
|
42
|
+
expect(ref).toHaveBeenCalledTimes(1)
|
|
43
|
+
})
|
|
44
|
+
})
|