@anker-in/headless-ui 0.0.5 → 0.0.7
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/CONTRIBUTING.md +18 -16
- package/README.md +9 -11
- package/dist/esm/components/badge.d.ts +1 -1
- package/dist/esm/components/badge.js +2 -0
- package/dist/esm/components/badge.js.map +7 -0
- package/dist/esm/components/button.d.ts +3 -2
- package/dist/esm/components/button.js +2 -0
- package/dist/esm/components/button.js.map +7 -0
- package/dist/esm/components/checkbox.js +2 -0
- package/dist/esm/components/checkbox.js.map +7 -0
- package/dist/esm/components/dialog.d.ts +2 -2
- package/dist/esm/components/dialog.js +2 -0
- package/dist/esm/components/dialog.js.map +7 -0
- package/dist/esm/components/heading.js +2 -0
- package/dist/esm/components/heading.js.map +7 -0
- package/dist/esm/components/index.d.ts +2 -1
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +7 -0
- package/dist/esm/components/input.d.ts +1 -1
- package/dist/esm/components/input.js +2 -0
- package/dist/esm/components/input.js.map +7 -0
- package/dist/esm/components/popover.js +2 -0
- package/dist/esm/components/popover.js.map +7 -0
- package/dist/esm/components/radio.js +2 -0
- package/dist/esm/components/radio.js.map +7 -0
- package/dist/esm/components/skeleton.d.ts +2 -2
- package/dist/esm/components/skeleton.js +2 -0
- package/dist/esm/components/skeleton.js.map +7 -0
- package/dist/esm/components/text.d.ts +6 -2
- package/dist/esm/components/text.js +2 -0
- package/dist/esm/components/text.js.map +7 -0
- package/dist/esm/components/theme.d.ts +7 -2
- package/dist/esm/components/theme.js +2 -0
- package/dist/esm/components/theme.js.map +7 -0
- package/dist/esm/helpers/component-props.js +1 -0
- package/dist/esm/helpers/component-props.js.map +7 -0
- package/dist/esm/helpers/constants.js +2 -0
- package/dist/esm/helpers/constants.js.map +7 -0
- package/dist/esm/helpers/index.js +2 -0
- package/dist/esm/helpers/index.js.map +7 -0
- package/dist/esm/helpers/utils.js +2 -0
- package/dist/esm/helpers/utils.js.map +7 -0
- package/dist/esm/icons/spinner.d.ts +1 -2
- package/dist/esm/icons/spinner.js +2 -0
- package/dist/esm/icons/spinner.js.map +7 -0
- package/dist/esm/index.js +1 -41
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/package.json +3 -0
- package/dist/esm/src/components/badge.d.ts +9 -0
- package/dist/esm/src/components/button.d.ts +20 -0
- package/dist/esm/src/components/checkbox.d.ts +4 -0
- package/dist/esm/src/components/dialog.d.ts +19 -0
- package/dist/esm/src/components/heading.d.ts +7 -0
- package/dist/esm/src/components/index.d.ts +11 -0
- package/dist/esm/src/components/input.d.ts +21 -0
- package/dist/esm/src/components/popover.d.ts +6 -0
- package/dist/esm/src/components/radio.d.ts +5 -0
- package/dist/esm/src/components/skeleton.d.ts +6 -0
- package/dist/esm/src/components/text.d.ts +12 -0
- package/dist/esm/src/components/theme.d.ts +13 -0
- package/dist/esm/src/helpers/component-props.d.ts +7 -0
- package/dist/esm/src/helpers/constants.d.ts +2 -0
- package/dist/esm/src/helpers/index.d.ts +1 -0
- package/dist/esm/src/helpers/utils.d.ts +2 -0
- package/dist/esm/src/icons/spinner.d.ts +7 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/stories/badge.stories.d.ts +26 -0
- package/dist/esm/src/stories/button.stories.d.ts +47 -0
- package/dist/esm/src/stories/checkbox.stories.d.ts +5 -0
- package/dist/esm/src/stories/dialog.stories.d.ts +5 -0
- package/dist/esm/src/stories/input.stories.d.ts +30 -0
- package/dist/esm/src/stories/popover.stories.d.ts +5 -0
- package/dist/esm/src/stories/radio.stories.d.ts +5 -0
- package/dist/esm/src/stories/skeleton.stories.d.ts +14 -0
- package/dist/esm/src/stories/text.stories.d.ts +16 -0
- package/dist/esm/stories/badge.stories.d.ts +1 -1
- package/dist/esm/stories/badge.stories.js +2 -0
- package/dist/esm/stories/badge.stories.js.map +7 -0
- package/dist/esm/stories/button.stories.d.ts +11 -3
- package/dist/esm/stories/button.stories.js +2 -0
- package/dist/esm/stories/button.stories.js.map +7 -0
- package/dist/esm/stories/checkbox.stories.d.ts +1 -2
- package/dist/esm/stories/checkbox.stories.js +2 -0
- package/dist/esm/stories/checkbox.stories.js.map +7 -0
- package/dist/esm/stories/dialog.stories.d.ts +1 -2
- package/dist/esm/stories/dialog.stories.js +2 -0
- package/dist/esm/stories/dialog.stories.js.map +7 -0
- package/dist/esm/stories/input.stories.d.ts +2 -2
- package/dist/esm/stories/input.stories.js +2 -0
- package/dist/esm/stories/input.stories.js.map +7 -0
- package/dist/esm/stories/popover.stories.d.ts +1 -2
- package/dist/esm/stories/popover.stories.js +2 -0
- package/dist/esm/stories/popover.stories.js.map +7 -0
- package/dist/esm/stories/radio.stories.d.ts +1 -2
- package/dist/esm/stories/radio.stories.js +2 -0
- package/dist/esm/stories/radio.stories.js.map +7 -0
- package/dist/esm/stories/skeleton.stories.js +2 -0
- package/dist/esm/stories/skeleton.stories.js.map +7 -0
- package/dist/esm/stories/text.stories.d.ts +16 -0
- package/dist/esm/stories/text.stories.js +2 -0
- package/dist/esm/stories/text.stories.js.map +7 -0
- package/dist/esm/tests/badge.test.d.ts +1 -0
- package/dist/esm/tests/button.test.d.ts +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +18 -16
- package/src/components/badge.tsx +1 -1
- package/src/components/button.tsx +34 -7
- package/src/components/checkbox.tsx +2 -0
- package/src/components/index.ts +3 -1
- package/src/components/input.tsx +2 -0
- package/src/components/popover.tsx +2 -0
- package/src/components/radio.tsx +2 -0
- package/src/components/skeleton.tsx +1 -1
- package/src/components/text.tsx +33 -5
- package/src/components/theme.tsx +10 -6
- package/src/stories/button.stories.tsx +8 -0
- package/src/stories/text.stories.tsx +37 -0
- package/src/styles/global.css +1 -1
- package/style.css +148 -218
- package/dist/style.css +0 -1352
- package/src/components/__tests__/button.test.js +0 -9
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
2
4
|
import { Slot } from '@radix-ui/react-slot'
|
|
3
5
|
import { VisuallyHidden } from '@radix-ui/react-visually-hidden'
|
|
4
|
-
import {
|
|
5
|
-
import { cn } from '../helpers/index'
|
|
6
|
+
import { type VariantProps, cva } from 'class-variance-authority'
|
|
6
7
|
import Spinner from '../icons/spinner'
|
|
8
|
+
import { cn } from '../helpers/index'
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Button Variants
|
|
@@ -26,10 +28,30 @@ const buttonVariants = cva(
|
|
|
26
28
|
lg: 'h-11 px-8',
|
|
27
29
|
icon: 'size-10 rounded-full',
|
|
28
30
|
},
|
|
31
|
+
/** hover 状态下的动画效果,需要注意不同variant 下的效果 */
|
|
32
|
+
hoverEffect: {
|
|
33
|
+
none: '',
|
|
34
|
+
slide: '',
|
|
35
|
+
},
|
|
29
36
|
},
|
|
37
|
+
compoundVariants: [
|
|
38
|
+
{
|
|
39
|
+
variant: 'primary',
|
|
40
|
+
hoverEffect: 'slide',
|
|
41
|
+
class:
|
|
42
|
+
'before:rounded-btn hover:bg-btn-primary before:bg-btn-primary-active relative overflow-hidden before:absolute before:inset-y-0 before:w-full before:-translate-x-full before:transition-transform before:duration-300 before:ease-in-out before:content-[""] hover:before:translate-x-0',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
variant: 'secondary',
|
|
46
|
+
hoverEffect: 'slide',
|
|
47
|
+
class:
|
|
48
|
+
'before:rounded-btn hover:bg-btn-secondary before:bg-btn-secondary-active relative overflow-hidden before:absolute before:inset-y-0 before:w-full before:-translate-x-full before:transition-transform before:duration-300 before:ease-in-out before:content-[""] hover:before:translate-x-0',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
30
51
|
defaultVariants: {
|
|
31
52
|
variant: 'primary',
|
|
32
53
|
size: 'base',
|
|
54
|
+
hoverEffect: 'none',
|
|
33
55
|
},
|
|
34
56
|
}
|
|
35
57
|
)
|
|
@@ -52,6 +74,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
52
74
|
size = 'base',
|
|
53
75
|
children,
|
|
54
76
|
variant,
|
|
77
|
+
hoverEffect = 'none',
|
|
55
78
|
className,
|
|
56
79
|
disabled = false,
|
|
57
80
|
loading = false,
|
|
@@ -64,9 +87,13 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
64
87
|
return (
|
|
65
88
|
<Comp
|
|
66
89
|
disabled={disabled}
|
|
67
|
-
className={cn(
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
className={cn(
|
|
91
|
+
buttonVariants({ variant, size, hoverEffect }),
|
|
92
|
+
{
|
|
93
|
+
'cursor-not-allowed': disabled,
|
|
94
|
+
},
|
|
95
|
+
className
|
|
96
|
+
)}
|
|
70
97
|
ref={ref}
|
|
71
98
|
{...props}
|
|
72
99
|
>
|
|
@@ -81,7 +108,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
81
108
|
<VisuallyHidden>{children}</VisuallyHidden>
|
|
82
109
|
</>
|
|
83
110
|
) : (
|
|
84
|
-
children
|
|
111
|
+
<span className="z-[1]">{children}</span>
|
|
85
112
|
)}
|
|
86
113
|
</Comp>
|
|
87
114
|
)
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// theme
|
|
2
|
-
export { default as Theme } from './theme'
|
|
2
|
+
// export { default as Theme } from './theme'
|
|
3
3
|
|
|
4
4
|
// components
|
|
5
5
|
export { default as Button } from './button'
|
|
@@ -13,3 +13,5 @@ export * from './dialog'
|
|
|
13
13
|
export * from './popover'
|
|
14
14
|
export * from './radio'
|
|
15
15
|
export * from './dialog'
|
|
16
|
+
export * from './text'
|
|
17
|
+
export { default as Theme } from './theme'
|
package/src/components/input.tsx
CHANGED
package/src/components/radio.tsx
CHANGED
package/src/components/text.tsx
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react'
|
|
2
2
|
import { Slot } from '@radix-ui/react-slot'
|
|
3
|
-
import
|
|
3
|
+
import { cn } from '../helpers'
|
|
4
|
+
import { VariantProps, cva } from 'class-variance-authority'
|
|
5
|
+
|
|
6
|
+
const textVariants = cva('', {
|
|
7
|
+
variants: {
|
|
8
|
+
size: {
|
|
9
|
+
1: 'text-xs',
|
|
10
|
+
2: 'text-sm',
|
|
11
|
+
3: 'text-base',
|
|
12
|
+
4: 'text-lg',
|
|
13
|
+
5: 'text-xl',
|
|
14
|
+
6: 'text-2xl',
|
|
15
|
+
7: 'text-3xl',
|
|
16
|
+
8: 'text-4xl',
|
|
17
|
+
9: 'text-5xl',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
})
|
|
4
21
|
|
|
5
22
|
type TextElement = React.ElementRef<'span'>
|
|
6
23
|
interface TextProps extends React.ComponentPropsWithoutRef<'span'> {
|
|
@@ -9,10 +26,20 @@ interface TextProps extends React.ComponentPropsWithoutRef<'span'> {
|
|
|
9
26
|
color?: string
|
|
10
27
|
}
|
|
11
28
|
|
|
12
|
-
const Text = React.forwardRef<TextElement, TextProps
|
|
13
|
-
const { children, className, asChild, as: Tag = 'span', color, ...textProps } = props
|
|
29
|
+
const Text = React.forwardRef<TextElement, TextProps & VariantProps<typeof textVariants>>((props, forwardedRef) => {
|
|
30
|
+
const { children, size, className, asChild, as: Tag = 'span', color, ...textProps } = props
|
|
14
31
|
return (
|
|
15
|
-
<Slot
|
|
32
|
+
<Slot
|
|
33
|
+
{...textProps}
|
|
34
|
+
ref={forwardedRef}
|
|
35
|
+
className={cn(
|
|
36
|
+
textVariants({
|
|
37
|
+
size: size,
|
|
38
|
+
}),
|
|
39
|
+
className,
|
|
40
|
+
color
|
|
41
|
+
)}
|
|
42
|
+
>
|
|
16
43
|
{asChild ? children : <Tag>{children}</Tag>}
|
|
17
44
|
</Slot>
|
|
18
45
|
)
|
|
@@ -20,3 +47,4 @@ const Text = React.forwardRef<TextElement, TextProps>((props, forwardedRef) => {
|
|
|
20
47
|
Text.displayName = 'Text'
|
|
21
48
|
|
|
22
49
|
export { Text }
|
|
50
|
+
export type { TextProps }
|
package/src/components/theme.tsx
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import * as React from 'react'
|
|
1
3
|
import type { Brand } from '@/helpers/constants'
|
|
2
|
-
import React, { useEffect } from 'react'
|
|
3
4
|
|
|
4
5
|
interface ThemeProps {
|
|
5
6
|
brand: Brand
|
|
6
7
|
children: React.ReactNode
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param param
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
8
14
|
const Theme = ({ brand, children }: ThemeProps) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, [brand])
|
|
13
|
-
|
|
15
|
+
React.useLayoutEffect(() => {
|
|
16
|
+
document.querySelector('html')?.setAttribute('data-brand-theme', brand)
|
|
17
|
+
}, [])
|
|
14
18
|
return <>{children}</>
|
|
15
19
|
}
|
|
16
20
|
|
|
@@ -29,6 +29,13 @@ const meta = {
|
|
|
29
29
|
},
|
|
30
30
|
options: ['sm', 'base', 'lg', 'icon'],
|
|
31
31
|
},
|
|
32
|
+
hoverEffect: {
|
|
33
|
+
description: 'hover 状态下的动画效果,仅在variant是primary 和 secondary 时生效',
|
|
34
|
+
control: {
|
|
35
|
+
type: 'select',
|
|
36
|
+
},
|
|
37
|
+
options: ['none', 'slide'],
|
|
38
|
+
},
|
|
32
39
|
},
|
|
33
40
|
args: {
|
|
34
41
|
variant: 'primary',
|
|
@@ -37,6 +44,7 @@ const meta = {
|
|
|
37
44
|
asChild: false,
|
|
38
45
|
disabled: false,
|
|
39
46
|
loading: false,
|
|
47
|
+
hoverEffect: 'none',
|
|
40
48
|
},
|
|
41
49
|
} satisfies Meta<typeof Button>
|
|
42
50
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
|
+
|
|
3
|
+
import { Text } from '../components/index'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Text',
|
|
8
|
+
component: Text,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
} satisfies Meta<typeof Text>
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj<typeof meta>
|
|
17
|
+
|
|
18
|
+
export const Default: Story = {
|
|
19
|
+
args: {
|
|
20
|
+
children: ' The quick brown fox jumps over the lazy dog.',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const sizes = new Array(10).fill(0).map((_, i) => i + 1)
|
|
25
|
+
export const All: Story = {
|
|
26
|
+
render() {
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{sizes.map(size => (
|
|
30
|
+
<Text as="p" key={size} size={size as any}>
|
|
31
|
+
The quick brown fox jumps over the lazy dog.
|
|
32
|
+
</Text>
|
|
33
|
+
))}
|
|
34
|
+
</>
|
|
35
|
+
)
|
|
36
|
+
},
|
|
37
|
+
}
|