@dafaz-ui/react 2.0.1 → 2.2.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.
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from 'react'
2
+ import { ButtonUI, ButtonUIProps } from './styles'
3
+
4
+ interface ButtonProps {
5
+ children: ReactNode
6
+ }
7
+
8
+ export function Button({
9
+ children,
10
+ variant = 'primary',
11
+ size = 'md',
12
+ ...props
13
+ }: ButtonUIProps & ButtonProps) {
14
+ return (
15
+ <ButtonUI variant={variant} size={size} {...props}>
16
+ {children}
17
+ </ButtonUI>
18
+ )
19
+ }
20
+
21
+ ButtonUI.displayName = 'Button'
@@ -1,9 +1,8 @@
1
- import type { ComponentProps } from '@stitches/react'
2
- import { styled } from '../styles'
3
- import type { ElementType } from 'react'
1
+ import type { ComponentProps, ElementType } from 'react'
2
+ import { styled } from '../../styles'
4
3
 
5
4
  /** Primary UI component for user interaction */
6
- export const Button = styled('button', {
5
+ export const ButtonUI = styled('button', {
7
6
  all: 'unset',
8
7
  borderRadius: '$md',
9
8
  fontSize: '$md',
@@ -25,11 +24,6 @@ export const Button = styled('button', {
25
24
  cursor: 'not-allowed',
26
25
  },
27
26
 
28
- svg: {
29
- width: '$4',
30
- height: '$4',
31
- },
32
-
33
27
  variants: {
34
28
  variant: {
35
29
  primary: {
@@ -76,29 +70,48 @@ export const Button = styled('button', {
76
70
  size: {
77
71
  sm: {
78
72
  height: 38,
73
+ fontSize: '$sm',
79
74
  },
80
75
  md: {
81
76
  height: 46,
77
+ fontSize: '$lg',
78
+ },
79
+ lg: {
80
+ height: 54,
81
+ fontSize: '$xl',
82
82
  },
83
83
  },
84
- },
84
+ flat: {
85
+ true: {
86
+ border: 0,
87
+ background: 'transparent',
85
88
 
89
+ '&:disabled': {
90
+ color: '$gray200',
91
+ background: 'transparent',
92
+ border: 'none',
93
+ },
94
+ },
95
+ false: {},
96
+ },
97
+ },
86
98
  defaultVariants: {
87
99
  variant: 'primary',
88
100
  size: 'md',
101
+ flat: false,
89
102
  },
90
103
  })
91
104
 
92
- export interface ButtonProps extends ComponentProps<typeof Button> {
105
+ export interface ButtonUIProps extends ComponentProps<typeof ButtonUI> {
93
106
  as?: ElementType
94
107
  /** How large should the button be? */
95
- size?: 'sm' | 'md'
108
+ size?: 'sm' | 'md' | 'lg'
96
109
  /** Optional click handler */
97
110
  onClick?: () => void
98
- /** Button contents */
99
- label: string
100
111
  /** Button is disable? */
101
112
  disabled?: boolean
102
113
  //** Button UI mode */
103
114
  variant?: 'primary' | 'secondary' | 'tertiary'
115
+ //** Flat mode */
116
+ flat?: boolean
104
117
  }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react'
2
+ import { HeadingUI, HeadingUIProps } from './styles'
3
+
4
+ interface HeadingProps {
5
+ children: ReactNode
6
+ }
7
+
8
+ export function Heading({ children, ...props }: HeadingUIProps & HeadingProps) {
9
+ return <HeadingUI {...props}>{children}</HeadingUI>
10
+ }
11
+
12
+ Heading.displayName = 'Heading'
@@ -0,0 +1,36 @@
1
+ import { ComponentProps, ElementType } from 'react'
2
+ import { styled } from '../../styles'
3
+
4
+ export const HeadingUI = styled('h2', {
5
+ fontFamily: '$web',
6
+ lineHeight: '$shorter',
7
+ margin: 0,
8
+
9
+ variants: {
10
+ mode: {
11
+ default: {
12
+ color: '$dafaz400',
13
+ },
14
+ white: {
15
+ color: '$white',
16
+ },
17
+ },
18
+ size: {
19
+ sm: { fontSize: '$lg' },
20
+ md: { fontSize: '$xl' },
21
+ lg: { fontSize: '$2xl' },
22
+ xl: { fontSize: '3rem' },
23
+ '2xl': { fontSize: '4rem' },
24
+ },
25
+ },
26
+ defaultVariants: {
27
+ mode: 'default',
28
+ size: 'lg',
29
+ },
30
+ })
31
+
32
+ export interface HeadingUIProps extends ComponentProps<typeof HeadingUI> {
33
+ as?: ElementType
34
+ size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl'
35
+ mode?: 'default' | 'white'
36
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react'
2
+ import { TextUI, TextUIProps } from './styles'
3
+
4
+ interface TextProps {
5
+ children: ReactNode
6
+ }
7
+
8
+ export function Text({
9
+ children,
10
+ size = 'md',
11
+ ...props
12
+ }: TextUIProps & TextProps) {
13
+ return (
14
+ <TextUI size={size} {...props}>
15
+ {children}
16
+ </TextUI>
17
+ )
18
+ }
19
+
20
+ Text.displayName = 'Text'
@@ -0,0 +1,30 @@
1
+ import { ComponentProps, ElementType } from 'react'
2
+ import { styled } from '../../styles'
3
+
4
+ export const TextUI = styled('p', {
5
+ fontFamily: '$web',
6
+ lineHeight: '$base',
7
+ margin: 0,
8
+ color: '$white',
9
+
10
+ variants: {
11
+ size: {
12
+ xxs: { fontSize: '$xxs' },
13
+ xs: { fontSize: '$xs' },
14
+ sm: { fontSize: '$sm' },
15
+ md: { fontSize: '$md' },
16
+ lg: { fontSize: '$lg' },
17
+ xl: { fontSize: '$xl' },
18
+ '2xl': { fontSize: '$2xl' },
19
+ },
20
+ },
21
+
22
+ defaultVariants: {
23
+ size: 'md',
24
+ },
25
+ })
26
+
27
+ export interface TextUIProps extends ComponentProps<typeof TextUI> {
28
+ as?: ElementType
29
+ size?: 'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
30
+ }
@@ -0,0 +1,53 @@
1
+ import {
2
+ forwardRef,
3
+ useState,
4
+ ComponentProps,
5
+ ElementRef,
6
+ type ChangeEvent,
7
+ } from 'react'
8
+ import { InputContainer, InputUI, Sufix } from './styles'
9
+
10
+ export interface TextInputProps extends ComponentProps<typeof InputUI> {
11
+ required?: boolean
12
+ requiredText?: string
13
+ withShadow?: boolean
14
+ placeholder?: string
15
+ type?: string
16
+ }
17
+
18
+ export const TextInput = forwardRef<ElementRef<typeof InputUI>, TextInputProps>(
19
+ (
20
+ {
21
+ withShadow = false,
22
+ required = true,
23
+ requiredText = 'Opcional',
24
+ ...props
25
+ }: TextInputProps,
26
+ ref,
27
+ ) => {
28
+ const [hiddenOptional, setHiddenOptional] = useState(required)
29
+
30
+ function handleOnChange(event: ChangeEvent<HTMLInputElement>) {
31
+ if (!required) {
32
+ if (event.target.value === '') {
33
+ setHiddenOptional(false)
34
+ } else {
35
+ setHiddenOptional(true)
36
+ }
37
+ }
38
+ }
39
+
40
+ return (
41
+ <InputContainer withShadow={withShadow}>
42
+ <InputUI ref={ref} onChange={handleOnChange} {...props} />
43
+ {!hiddenOptional && (
44
+ <Sufix style={{ marginLeft: `-${requiredText.length / 2}rem` }}>
45
+ {requiredText}
46
+ </Sufix>
47
+ )}
48
+ </InputContainer>
49
+ )
50
+ },
51
+ )
52
+
53
+ TextInput.displayName = 'Input'
@@ -0,0 +1,68 @@
1
+ import { styled } from '../../styles'
2
+
3
+ export const InputContainer = styled('div', {
4
+ margin: 0,
5
+ backgroundColor: 'transparent',
6
+ borderBottom: '2px solid $dafaz600',
7
+ borderRadius: '$md',
8
+ boxSizing: 'border-box',
9
+ display: 'flex',
10
+ alignItems: 'baseline',
11
+ padding: '$1 $2',
12
+
13
+ transition: 'border 0.2s linear',
14
+
15
+ '&:has(input:focus)': {
16
+ borderBottom: '2px solid $dafaz400',
17
+ },
18
+
19
+ '&:has(input:disabled)': {
20
+ opacity: 0.5,
21
+ cursor: 'not-allowed',
22
+ },
23
+
24
+ variants: {
25
+ withShadow: {
26
+ true: {
27
+ boxShadow: 'inset 0 2.5rem #444',
28
+ },
29
+ },
30
+ },
31
+ defaultVariants: {
32
+ withShadow: false,
33
+ },
34
+ })
35
+
36
+ export const InputUI = styled('input', {
37
+ margin: 0,
38
+ fontFamily: '$app',
39
+ fontSize: '$xl',
40
+ color: '$white',
41
+ backgroundColor: 'transparent',
42
+ border: 'none',
43
+
44
+ '&::-ms-reveal': {
45
+ filter: 'invert(100%)',
46
+ },
47
+
48
+ '&::placeholder': {
49
+ fontWeight: '$regular',
50
+ color: '$white',
51
+ opacity: 0.75,
52
+ },
53
+
54
+ '&:focus': {
55
+ outline: 0,
56
+ },
57
+ })
58
+
59
+ export const Sufix = styled('span', {
60
+ fontFamily: '$app',
61
+ fontSize: '$sm',
62
+ color: '$white',
63
+ fontStyle: 'italic',
64
+
65
+ '&:has(input:focus)': {
66
+ visibility: 'hidden',
67
+ },
68
+ })
package/src/index.tsx CHANGED
@@ -1,3 +1,7 @@
1
+ export * from './components/Box'
1
2
  export * from './components/Button'
3
+ export * from './components/Text'
4
+ export * from './components/Heading'
5
+ export * from './components/TextInput'
2
6
 
3
7
  export * from './styles'