@anker-in/headless-ui 0.0.11 → 0.0.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 (86) hide show
  1. package/CONTRIBUTING.md +6 -1
  2. package/dist/cjs/components/checkbox.d.ts +8 -1
  3. package/dist/cjs/components/checkbox.js +1 -1
  4. package/dist/cjs/components/checkbox.js.map +3 -3
  5. package/dist/cjs/components/heading.d.ts +9 -1
  6. package/dist/cjs/components/heading.js +1 -1
  7. package/dist/cjs/components/heading.js.map +3 -3
  8. package/dist/cjs/components/index.d.ts +1 -0
  9. package/dist/cjs/components/index.js +1 -1
  10. package/dist/cjs/components/index.js.map +2 -2
  11. package/dist/cjs/components/input.d.ts +1 -1
  12. package/dist/cjs/components/input.js.map +1 -1
  13. package/dist/cjs/components/radio.d.ts +13 -2
  14. package/dist/cjs/components/radio.js +1 -1
  15. package/dist/cjs/components/radio.js.map +3 -3
  16. package/dist/cjs/components/skeleton.d.ts +6 -3
  17. package/dist/cjs/components/skeleton.js +4 -1
  18. package/dist/cjs/components/skeleton.js.map +3 -3
  19. package/dist/cjs/components/text.js +1 -1
  20. package/dist/cjs/components/text.js.map +3 -3
  21. package/dist/cjs/stories/checkbox.stories.d.ts +44 -3
  22. package/dist/cjs/stories/checkbox.stories.js +1 -1
  23. package/dist/cjs/stories/checkbox.stories.js.map +3 -3
  24. package/dist/cjs/stories/heading.stories.d.ts +68 -0
  25. package/dist/cjs/stories/heading.stories.js +2 -0
  26. package/dist/cjs/stories/heading.stories.js.map +7 -0
  27. package/dist/cjs/stories/radio.stories.d.ts +34 -3
  28. package/dist/cjs/stories/radio.stories.js +1 -1
  29. package/dist/cjs/stories/radio.stories.js.map +3 -3
  30. package/dist/cjs/stories/skeleton.stories.d.ts +9 -3
  31. package/dist/cjs/stories/skeleton.stories.js +1 -1
  32. package/dist/cjs/stories/skeleton.stories.js.map +3 -3
  33. package/dist/cjs/stories/text.stories.d.ts +33 -1
  34. package/dist/cjs/stories/text.stories.js +9 -1
  35. package/dist/cjs/stories/text.stories.js.map +3 -3
  36. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  37. package/dist/esm/components/checkbox.d.ts +8 -1
  38. package/dist/esm/components/checkbox.js +1 -1
  39. package/dist/esm/components/checkbox.js.map +3 -3
  40. package/dist/esm/components/heading.d.ts +9 -1
  41. package/dist/esm/components/heading.js +1 -1
  42. package/dist/esm/components/heading.js.map +3 -3
  43. package/dist/esm/components/index.d.ts +1 -0
  44. package/dist/esm/components/index.js +1 -1
  45. package/dist/esm/components/index.js.map +2 -2
  46. package/dist/esm/components/input.d.ts +1 -1
  47. package/dist/esm/components/input.js.map +1 -1
  48. package/dist/esm/components/radio.d.ts +13 -2
  49. package/dist/esm/components/radio.js +1 -1
  50. package/dist/esm/components/radio.js.map +3 -3
  51. package/dist/esm/components/skeleton.d.ts +6 -3
  52. package/dist/esm/components/skeleton.js +4 -1
  53. package/dist/esm/components/skeleton.js.map +3 -3
  54. package/dist/esm/components/text.js +1 -1
  55. package/dist/esm/components/text.js.map +3 -3
  56. package/dist/esm/stories/checkbox.stories.d.ts +44 -3
  57. package/dist/esm/stories/checkbox.stories.js +1 -1
  58. package/dist/esm/stories/checkbox.stories.js.map +3 -3
  59. package/dist/esm/stories/heading.stories.d.ts +68 -0
  60. package/dist/esm/stories/heading.stories.js +2 -0
  61. package/dist/esm/stories/heading.stories.js.map +7 -0
  62. package/dist/esm/stories/radio.stories.d.ts +34 -3
  63. package/dist/esm/stories/radio.stories.js +1 -1
  64. package/dist/esm/stories/radio.stories.js.map +3 -3
  65. package/dist/esm/stories/skeleton.stories.d.ts +9 -3
  66. package/dist/esm/stories/skeleton.stories.js +1 -1
  67. package/dist/esm/stories/skeleton.stories.js.map +3 -3
  68. package/dist/esm/stories/text.stories.d.ts +33 -1
  69. package/dist/esm/stories/text.stories.js +9 -1
  70. package/dist/esm/stories/text.stories.js.map +3 -3
  71. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +1 -1
  73. package/src/components/checkbox.tsx +33 -17
  74. package/src/components/heading.tsx +59 -4
  75. package/src/components/index.ts +1 -0
  76. package/src/components/input.tsx +1 -1
  77. package/src/components/radio.tsx +60 -25
  78. package/src/components/skeleton.tsx +33 -2
  79. package/src/components/text.tsx +13 -4
  80. package/src/stories/checkbox.stories.tsx +80 -3
  81. package/src/stories/heading.stories.tsx +88 -0
  82. package/src/stories/radio.stories.tsx +51 -15
  83. package/src/stories/skeleton.stories.tsx +36 -2
  84. package/src/stories/text.stories.tsx +68 -10
  85. package/src/styles/global.css +5 -5
  86. package/style.css +70 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anker-in/headless-ui",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "type": "commonjs",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
@@ -5,24 +5,40 @@ import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
5
5
  import { CheckIcon } from '@radix-ui/react-icons'
6
6
 
7
7
  import { cn } from '../helpers/index.js'
8
+ import { cva, type VariantProps } from 'class-variance-authority'
8
9
 
9
- const Checkbox = React.forwardRef<
10
- React.ElementRef<typeof CheckboxPrimitive.Root>,
11
- React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
12
- >(({ className, ...props }, ref) => (
13
- <CheckboxPrimitive.Root
14
- ref={ref}
15
- className={cn(
16
- 'ai-border-primary ai-ring-offset-background focus-visible:ai-ring-ring data-[state=checked]:ai-bg-primary data-[state=checked]:ai-text-primary-foreground ai-peer ai-size-4 ai-shrink-0 ai-rounded-sm ai-border focus-visible:ai-outline-none focus-visible:ai-ring-2 focus-visible:ai-ring-offset-2 disabled:ai-cursor-not-allowed disabled:ai-opacity-50',
17
- className
18
- )}
19
- {...props}
20
- >
21
- <CheckboxPrimitive.Indicator className={cn('ai-flex ai-items-center ai-justify-center ai-text-current')}>
22
- <CheckIcon className="ai-size-4" />
23
- </CheckboxPrimitive.Indicator>
24
- </CheckboxPrimitive.Root>
25
- ))
10
+ const checkboxVariants = cva(
11
+ 'ai-border-primary ai-ring-offset-background focus-visible:ai-ring-ring data-[state=checked]:ai-bg-primary data-[state=checked]:ai-text-primary-foreground ai-peer ai-shrink-0 ai-rounded-sm ai-border focus-visible:ai-outline-none focus-visible:ai-ring-2 focus-visible:ai-ring-offset-2 disabled:ai-cursor-not-allowed disabled:ai-opacity-50 disabled:ai-bg-btn-primary-disabled',
12
+ {
13
+ variants: {
14
+ size: {
15
+ sm: 'ai-size-[14px]',
16
+ base: 'ai-size-4',
17
+ lg: 'ai-size-5',
18
+ },
19
+ },
20
+ defaultVariants: {
21
+ size: 'base',
22
+ },
23
+ }
24
+ )
25
+
26
+ interface CheckboxProps
27
+ extends React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>,
28
+ VariantProps<typeof checkboxVariants> {}
29
+
30
+ const Checkbox = React.forwardRef<React.ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
31
+ ({ className, size, ...props }, ref) => (
32
+ <CheckboxPrimitive.Root ref={ref} className={cn(checkboxVariants({ size }), className)} {...props}>
33
+ <CheckboxPrimitive.Indicator
34
+ className={cn('ai-flex ai-items-center ai-justify-center ai-text-current ai-w-full ai-h-full')}
35
+ >
36
+ <CheckIcon />
37
+ </CheckboxPrimitive.Indicator>
38
+ </CheckboxPrimitive.Root>
39
+ )
40
+ )
26
41
  Checkbox.displayName = CheckboxPrimitive.Root.displayName
27
42
 
28
43
  export default Checkbox
44
+ export type { CheckboxProps }
@@ -1,19 +1,73 @@
1
1
  import { cn } from '../helpers/index.js'
2
2
  import { Slot } from '@radix-ui/react-slot'
3
+ import { cva, type VariantProps } from 'class-variance-authority'
3
4
  import React from 'react'
4
5
 
6
+ const headingVariants = cva('', {
7
+ variants: {
8
+ size: {
9
+ 1: 'ai-text-xs',
10
+ 2: 'ai-text-sm',
11
+ 3: 'ai-text-base',
12
+ 4: 'ai-text-lg',
13
+ 5: 'ai-text-xl',
14
+ 6: 'ai-text-2xl',
15
+ 7: 'ai-text-3xl',
16
+ 8: 'ai-text-4xl',
17
+ 9: 'ai-text-5xl',
18
+ },
19
+ weights: {
20
+ light: 'ai-font-light',
21
+ normal: 'ai-font-normal',
22
+ medium: 'ai-font-medium',
23
+ bold: 'ai-font-bold',
24
+ },
25
+ },
26
+ defaultVariants: {
27
+ size: 3,
28
+ weights: 'normal',
29
+ },
30
+ })
31
+
5
32
  type HeadingElement = React.ElementRef<'h1'>
6
33
 
7
- interface HeadingProps extends React.ComponentPropsWithoutRef<'h1'> {
34
+ interface HeadingProps extends React.ComponentPropsWithoutRef<'h1'>, VariantProps<typeof headingVariants> {
8
35
  as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | undefined
9
36
  asChild?: boolean
37
+ color?: string
38
+ html?: string
10
39
  }
11
40
 
12
41
  const Heading = React.forwardRef<HeadingElement, HeadingProps>((props, forwardedRef) => {
13
- const { children, className, asChild, as: Tag = 'h1', color, ...headingProps } = props
42
+ const { children, className, size, weights, asChild, as: Tag = 'h1', color, html, ...headingProps } = props
43
+ const htmlContentProps = html
44
+ ? {
45
+ dangerouslySetInnerHTML: { __html: html },
46
+ }
47
+ : null
48
+
49
+ const styleProps = color
50
+ ? {
51
+ style: {
52
+ color,
53
+ },
54
+ }
55
+ : null
14
56
  return (
15
- <Slot data-accent-color={color || undefined} {...headingProps} ref={forwardedRef} className={cn('', className)}>
16
- {asChild ? children : <Tag>{children}</Tag>}
57
+ <Slot
58
+ {...headingProps}
59
+ ref={forwardedRef}
60
+ className={cn(
61
+ headingVariants({
62
+ size,
63
+ weights,
64
+ }),
65
+ className
66
+ )}
67
+ {...htmlContentProps}
68
+ {...styleProps}
69
+ >
70
+ {asChild ? children : <Tag>{htmlContentProps ? null : children}</Tag>}
17
71
  </Slot>
18
72
  )
19
73
  })
@@ -21,3 +75,4 @@ const Heading = React.forwardRef<HeadingElement, HeadingProps>((props, forwarded
21
75
  Heading.displayName = 'Heading'
22
76
 
23
77
  export { Heading }
78
+ export type { HeadingProps }
@@ -14,4 +14,5 @@ export * from './popover.js'
14
14
  export * from './radio.js'
15
15
  export * from './dialog.js'
16
16
  export * from './text.js'
17
+ export * from './heading.js'
17
18
  export { default as Theme } from './theme.js'
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { cn } from '../helpers/index.js'
5
- import type { ComponentPropsWithout, RemovedProps } from '@/helpers/component-props'
5
+ import type { ComponentPropsWithout, RemovedProps } from '../helpers/component-props.js'
6
6
  import { cva, type VariantProps } from 'class-variance-authority'
7
7
 
8
8
  const inputVariants = cva(
@@ -3,36 +3,71 @@
3
3
  import * as React from 'react'
4
4
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group'
5
5
  import { CheckIcon } from '@radix-ui/react-icons'
6
-
6
+ import { cva, type VariantProps } from 'class-variance-authority'
7
7
  import { cn } from '../helpers/index.js'
8
8
 
9
- const RadioGroup = React.forwardRef<
10
- React.ElementRef<typeof RadioGroupPrimitive.Root>,
11
- React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
12
- >(({ className, ...props }, ref) => {
13
- return <RadioGroupPrimitive.Root className={cn('grid gap-2', className)} {...props} ref={ref} />
9
+ const RadioContext = React.createContext<{ size?: 'sm' | 'base' | 'lg' }>({
10
+ size: 'base',
14
11
  })
12
+
13
+ const radioGroupVariants = cva(
14
+ 'ai-border-primary ai-text-primary ai-ring-offset-background focus-visible:ai-ring-ring ai-aspect-square ai-rounded-full ai-border focus:ai-outline-none focus-visible:ai-ring-2 focus-visible:ai-ring-offset-2 disabled:ai-cursor-not-allowed disabled:ai-opacity-50 data-[state=checked]:ai-bg-primary data-[state=checked]:ai-text-primary-foreground',
15
+ {
16
+ variants: {
17
+ size: {
18
+ sm: 'ai-size-[14px]',
19
+ base: 'ai-size-4',
20
+ lg: 'ai-size-5',
21
+ },
22
+ },
23
+ defaultVariants: {
24
+ size: 'base',
25
+ },
26
+ }
27
+ )
28
+
29
+ interface RadioGroupProps extends React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root> {
30
+ /** 尺寸 */
31
+ size?: 'sm' | 'base' | 'lg'
32
+ }
33
+
34
+ const RadioGroup = React.forwardRef<React.ElementRef<typeof RadioGroupPrimitive.Root>, RadioGroupProps>(
35
+ ({ className, children, size, ...props }, ref) => {
36
+ return (
37
+ <RadioGroupPrimitive.Root className={cn('grid gap-2', className)} {...props} ref={ref}>
38
+ <RadioContext.Provider value={{ size }}>{children}</RadioContext.Provider>
39
+ </RadioGroupPrimitive.Root>
40
+ )
41
+ }
42
+ )
15
43
  RadioGroup.displayName = RadioGroupPrimitive.Root.displayName
16
44
 
17
- const RadioGroupItem = React.forwardRef<
18
- React.ElementRef<typeof RadioGroupPrimitive.Item>,
19
- React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
20
- >(({ className, ...props }, ref) => {
21
- return (
22
- <RadioGroupPrimitive.Item
23
- ref={ref}
24
- className={cn(
25
- 'ai-border-primary ai-text-primary ai-ring-offset-background focus-visible:ai-ring-ring ai-aspect-square ai-size-4 ai-rounded-full ai-border focus:ai-outline-none focus-visible:ai-ring-2 focus-visible:ai-ring-offset-2 disabled:ai-cursor-not-allowed disabled:ai-opacity-50',
26
- className
27
- )}
28
- {...props}
29
- >
30
- <RadioGroupPrimitive.Indicator className="ai-flex ai-items-center ai-justify-center">
31
- <CheckIcon className="ai-text-primary ai-size-2.5 ai-fill-current" />
32
- </RadioGroupPrimitive.Indicator>
33
- </RadioGroupPrimitive.Item>
34
- )
35
- })
45
+ interface RadioGroupItemProps
46
+ extends React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>,
47
+ VariantProps<typeof radioGroupVariants> {}
48
+
49
+ const RadioGroupItem = React.forwardRef<React.ElementRef<typeof RadioGroupPrimitive.Item>, RadioGroupItemProps>(
50
+ ({ className, size, ...props }, ref) => {
51
+ const { size: sizeFromParent } = React.useContext(RadioContext)
52
+ return (
53
+ <RadioGroupPrimitive.Item
54
+ ref={ref}
55
+ className={cn(
56
+ radioGroupVariants({
57
+ size: size ?? sizeFromParent,
58
+ }),
59
+ className
60
+ )}
61
+ {...props}
62
+ >
63
+ <RadioGroupPrimitive.Indicator className="ai-flex ai-items-center ai-justify-center ai-text-current ai-w-full ai-h-full">
64
+ <CheckIcon />
65
+ </RadioGroupPrimitive.Indicator>
66
+ </RadioGroupPrimitive.Item>
67
+ )
68
+ }
69
+ )
36
70
  RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName
37
71
 
38
72
  export { RadioGroup, RadioGroupItem }
73
+ export type { RadioGroupProps, RadioGroupItemProps }
@@ -1,10 +1,41 @@
1
1
  import * as React from 'react'
2
2
  import { cn } from '../helpers/index.js'
3
+ import { Slot } from '@radix-ui/react-slot'
4
+ import type { ComponentPropsWithout, RemovedProps } from '../helpers/component-props.js'
3
5
 
4
- function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
5
- return <div className={cn('ai-bg-skeleton ai-size-12 ai-animate-pulse', className)} {...props} />
6
+ type SkeletonElement = React.ElementRef<'span'>
7
+
8
+ interface SkeletonProps extends ComponentPropsWithout<'span', RemovedProps> {
9
+ /** 是否正在加载 */
10
+ loading?: boolean
6
11
  }
7
12
 
13
+ const Skeleton = React.forwardRef<SkeletonElement, SkeletonProps>((props, forwardedRef) => {
14
+ const { children, className, loading = true, ...skeletonProps } = props
15
+
16
+ if (!loading) return children
17
+ const Tag = React.isValidElement(children) ? Slot : 'span'
18
+
19
+ return (
20
+ <Tag
21
+ ref={forwardedRef}
22
+ className={cn(
23
+ `ai-bg-skeleton ai-animate-pulse empty:ai-block data-[inline-skeleton=true]:ai-leading-[0] !ai-bg-none !ai-bg-clip-border !ai-border-none !ai-shadow-none
24
+ !ai-text-transparent !ai-outline-none !ai-select-none !ai-cursor-default !ai-pointer-events-none !ai-decoration-clone
25
+ after:!ai-invisible before:!ai-invisible [&>*]:!ai-invisible
26
+ `,
27
+ className
28
+ )}
29
+ data-inline-skeleton={React.isValidElement(children) ? undefined : true}
30
+ tabIndex={-1}
31
+ {...skeletonProps}
32
+ >
33
+ {children}
34
+ </Tag>
35
+ )
36
+ })
37
+
8
38
  Skeleton.displayName = 'Skeleton'
9
39
 
10
40
  export default Skeleton
41
+ export type { SkeletonProps }
@@ -39,7 +39,7 @@ interface TextProps extends React.ComponentPropsWithoutRef<'span'>, VariantProps
39
39
  }
40
40
 
41
41
  const Text = React.forwardRef<TextElement, TextProps>((props, forwardedRef) => {
42
- const { children, size, className, asChild, as: Tag = 'span', color, html, ...textProps } = props
42
+ const { children, size, weights, className, asChild, as: Tag = 'span', color, html, ...textProps } = props
43
43
 
44
44
  const htmlContentProps = html
45
45
  ? {
@@ -47,18 +47,27 @@ const Text = React.forwardRef<TextElement, TextProps>((props, forwardedRef) => {
47
47
  }
48
48
  : null
49
49
 
50
+ const styleProps = color
51
+ ? {
52
+ style: {
53
+ color,
54
+ },
55
+ }
56
+ : null
57
+
50
58
  return (
51
59
  <Slot
52
60
  {...textProps}
53
61
  ref={forwardedRef}
54
62
  className={cn(
55
63
  textVariants({
56
- size: size,
64
+ size,
65
+ weights,
57
66
  }),
58
- className,
59
- `text-[${color}]`
67
+ className
60
68
  )}
61
69
  {...htmlContentProps}
70
+ {...styleProps}
62
71
  >
63
72
  {asChild ? children : <Tag>{htmlContentProps ? null : children}</Tag>}
64
73
  </Slot>
@@ -1,11 +1,88 @@
1
+ import type { Meta, StoryObj } from '@storybook/react/*'
1
2
  import { Checkbox } from '../components/index'
2
3
  import React from 'react'
3
4
 
4
- export default { title: 'Components/Checkbox' }
5
+ const meta = {
6
+ title: 'Components/Checkbox',
7
+ component: Checkbox,
8
+ parameters: {
9
+ layout: 'centered',
10
+ docs: {
11
+ description: {
12
+ component: '复选框, 基于@radix-ui/react-checkbox https://www.radix-ui.com/primitives/docs/components/checkbox',
13
+ },
14
+ },
15
+ },
16
+ tags: ['autodocs'],
17
+ argTypes: {
18
+ size: {
19
+ control: {
20
+ type: 'select',
21
+ },
22
+ options: ['sm', 'base', 'lg'],
23
+ description: '尺寸',
24
+ table: {
25
+ defaultValue: { summary: 'base' },
26
+ },
27
+ },
28
+ },
29
+ args: {
30
+ size: 'base',
31
+ },
32
+ } satisfies Meta<typeof Checkbox>
5
33
 
6
- export const Default = () => (
34
+ export default meta
35
+
36
+ type Story = StoryObj<typeof meta>
37
+
38
+ export const Default: Story = {
39
+ args: {
40
+ size: 'base',
41
+ },
42
+ }
43
+
44
+ export const Sizes = () => (
45
+ <div className="ai-flex ai-flex-col ai-gap-2">
46
+ <div className="ai-flex ai-items-center ai-space-x-2">
47
+ <Checkbox id="terms" size="sm" />
48
+ <label
49
+ htmlFor="terms"
50
+ className="ai-text-sm ai-font-medium ai-leading-none peer-disabled:ai-cursor-not-allowed peer-disabled:ai-opacity-70"
51
+ >
52
+ Accept terms and conditions
53
+ </label>
54
+ </div>
55
+ <div className="ai-flex ai-items-center ai-space-x-2">
56
+ <Checkbox id="terms1" size="base" />
57
+ <label
58
+ htmlFor="terms1"
59
+ className="ai-text-base ai-font-medium ai-leading-none peer-disabled:ai-cursor-not-allowed peer-disabled:ai-opacity-70"
60
+ >
61
+ Accept terms and conditions
62
+ </label>
63
+ </div>
64
+ <div className="ai-flex ai-items-center ai-space-x-2">
65
+ <Checkbox id="terms2" size="lg" />
66
+ <label
67
+ htmlFor="terms2"
68
+ className="ai-text-lg ai-font-medium ai-leading-none peer-disabled:ai-cursor-not-allowed peer-disabled:ai-opacity-70"
69
+ >
70
+ Accept terms and conditions
71
+ </label>
72
+ </div>
73
+ </div>
74
+ )
75
+ Sizes.parameters = {
76
+ docs: {
77
+ description: {
78
+ story: '不同的尺寸',
79
+ },
80
+ },
81
+ }
82
+
83
+ export const Disabled = () => (
7
84
  <div className="ai-flex ai-items-center ai-space-x-2">
8
- <Checkbox id="terms" />
85
+ <Checkbox id="terms" disabled />
9
86
  <label
10
87
  htmlFor="terms"
11
88
  className="ai-text-sm ai-font-medium ai-leading-none peer-disabled:ai-cursor-not-allowed peer-disabled:ai-opacity-70"
@@ -0,0 +1,88 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+
3
+ import { Heading } from '../components/index'
4
+ import React from 'react'
5
+
6
+ const meta = {
7
+ title: 'Typography/Heading',
8
+ component: Heading,
9
+ parameters: {
10
+ layout: 'centered',
11
+ docs: {
12
+ description: {
13
+ component: 'Heading 组件, 基本和text 组件一样,只是默认的标签类型不一样',
14
+ },
15
+ },
16
+ },
17
+ tags: ['autodocs'],
18
+ argTypes: {
19
+ size: {
20
+ control: {
21
+ type: 'select',
22
+ },
23
+ options: [1, 2, 3, 4, 5, 6, 7, 8, 9],
24
+ description: '1~9',
25
+ table: {
26
+ defaultValue: { summary: '3' },
27
+ },
28
+ },
29
+ weights: {
30
+ control: {
31
+ type: 'select',
32
+ },
33
+ options: ['light', 'normal', 'medium', 'bold'],
34
+ table: {
35
+ defaultValue: { summary: 'normal' },
36
+ },
37
+ },
38
+ color: {
39
+ control: 'color',
40
+ },
41
+ as: {
42
+ control: {
43
+ type: 'select',
44
+ },
45
+ options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
46
+ description: 'html 标签类型',
47
+ table: {
48
+ defaultValue: { summary: 'h1' },
49
+ },
50
+ },
51
+ html: {
52
+ type: 'string',
53
+ description: '相当于 dangerouslySetInnerHTML',
54
+ },
55
+ },
56
+ args: {
57
+ as: 'h1',
58
+ size: 3,
59
+ weights: 'normal',
60
+ },
61
+ } satisfies Meta<typeof Heading>
62
+
63
+ export default meta
64
+
65
+ type Story = StoryObj<typeof meta>
66
+
67
+ export const Default: Story = {
68
+ args: {
69
+ as: 'h1',
70
+ children: ' The quick brown fox jumps over the lazy dog.',
71
+ },
72
+ }
73
+
74
+ export const All: Story = {
75
+ render: () => (
76
+ <>
77
+ <Heading size={1}>The quick brown fox jumps over the lazy dog.</Heading>
78
+ <Heading size={2}>The quick brown fox jumps over the lazy dog.</Heading>
79
+ <Heading size={3}>The quick brown fox jumps over the lazy dog.</Heading>
80
+ <Heading size={4}>The quick brown fox jumps over the lazy dog.</Heading>
81
+ <Heading size={5}>The quick brown fox jumps over the lazy dog.</Heading>
82
+ <Heading size={6}>The quick brown fox jumps over the lazy dog.</Heading>
83
+ <Heading size={7}>The quick brown fox jumps over the lazy dog.</Heading>
84
+ <Heading size={8}>The quick brown fox jumps over the lazy dog.</Heading>
85
+ <Heading size={9}>The quick brown fox jumps over the lazy dog.</Heading>
86
+ </>
87
+ ),
88
+ }
@@ -1,19 +1,55 @@
1
+ import type { Meta, StoryObj } from '@storybook/react/*'
1
2
  import { RadioGroup, RadioGroupItem } from '../components/index'
2
3
  import React from 'react'
3
4
 
4
- export default { title: 'Components/Radio' }
5
+ const meta = {
6
+ title: 'Components/Radio',
7
+ component: RadioGroup,
8
+ // subcomponents: { RadioGroupItem },
9
+ parameters: {
10
+ layout: 'centered',
11
+ docs: {
12
+ description: {
13
+ component:
14
+ '单选框, 基于@radix-ui/react-radio-group https://www.radix-ui.com/primitives/docs/components/radio-group',
15
+ },
16
+ },
17
+ },
18
+ tags: ['autodocs'],
19
+ argTypes: {
20
+ size: {
21
+ control: {
22
+ type: 'select',
23
+ },
24
+ options: ['sm', 'base', 'lg'],
25
+ description: '尺寸',
26
+ table: {
27
+ defaultValue: { summary: 'base' },
28
+ },
29
+ },
30
+ },
31
+ args: {
32
+ size: 'base',
33
+ },
34
+ } satisfies Meta<typeof RadioGroup>
5
35
 
6
- export const Default = () => (
7
- <div className="ai-flex ai-h-40 ai-w-48 ai-items-center ai-justify-center">
8
- <RadioGroup defaultValue="ai-option-one">
9
- <div className="ai-flex ai-items-center ai-space-x-2">
10
- <RadioGroupItem value="option-one" id="option-one" />
11
- <label htmlFor="option-one">Option One</label>
12
- </div>
13
- <div className="ai-flex ai-items-center ai-space-x-2">
14
- <RadioGroupItem value="option-two" id="option-two" />
15
- <label htmlFor="option-two">Option Two</label>
16
- </div>
17
- </RadioGroup>
18
- </div>
19
- )
36
+ export default meta
37
+
38
+ type Story = StoryObj<typeof RadioGroup>
39
+ export const Default: Story = {
40
+ args: {
41
+ size: 'base',
42
+ children: (
43
+ <>
44
+ <div className="ai-flex ai-items-center ai-space-x-2">
45
+ <RadioGroupItem value="option-one" id="option-one" />
46
+ <label htmlFor="option-one">Option One</label>
47
+ </div>
48
+ <div className="ai-flex ai-items-center ai-space-x-2">
49
+ <RadioGroupItem value="option-two" id="option-two" />
50
+ <label htmlFor="option-two">Option Two</label>
51
+ </div>
52
+ </>
53
+ ),
54
+ },
55
+ }
@@ -8,6 +8,12 @@ const meta = {
8
8
  component: Skeleton,
9
9
  parameters: {
10
10
  layout: 'centered',
11
+ docs: {
12
+ description: {
13
+ component:
14
+ '骨架屏组件,用来在数据加载时展示一个占位图, 可以包在dom 外使用,通过loading 控制显示隐藏, 也可以单独使用,通过自定义class控制样式, 组合成想要的形状',
15
+ },
16
+ },
11
17
  },
12
18
  tags: ['autodocs'],
13
19
  } satisfies Meta<typeof Skeleton>
@@ -16,9 +22,19 @@ export default meta
16
22
 
17
23
  type Story = StoryObj<typeof meta>
18
24
 
19
- export const Default: Story = {}
25
+ export const Default: Story = {
26
+ args: {
27
+ loading: true,
28
+ children: (
29
+ <div className="ai-h-14 ai-rounded-3xl ai-overflow-hidden ai-px-4 ai-py-4 w-full">
30
+ Fog creeps across moors, hills, and rivers. It adds an eerie charm to the landscape, but also complicates
31
+ driving.
32
+ </div>
33
+ ),
34
+ },
35
+ }
20
36
 
21
- export const Example: Story = {
37
+ export const Multiple: Story = {
22
38
  render() {
23
39
  return (
24
40
  <div className="ai-flex ai-flex-col ai-items-center ai-justify-center">
@@ -31,3 +47,21 @@ export const Example: Story = {
31
47
  )
32
48
  },
33
49
  }
50
+
51
+ export const WithText: Story = {
52
+ render() {
53
+ return (
54
+ <>
55
+ <Skeleton loading={true}>
56
+ Rainfall is a constant companion. Umbrellas are practically a national accessory. Expect drizzles, showers,
57
+ and downpours, often accompanied by gray skies.
58
+ </Skeleton>
59
+ <hr />
60
+ <Skeleton loading={false}>
61
+ Rainfall is a constant companion. Umbrellas are practically a national accessory. Expect drizzles, showers,
62
+ and downpours, often accompanied by gray skies.
63
+ </Skeleton>
64
+ </>
65
+ )
66
+ },
67
+ }