@infonomic/uikit 5.9.0 → 5.11.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/dist/components/button/@types/button.d.ts +1 -1
- package/dist/components/button/@types/button.d.ts.map +1 -1
- package/dist/components/button/@types/button.js +1 -0
- package/dist/components/button/button.module.css +107 -28
- package/dist/components/button/button.module.js +2 -0
- package/dist/components/button/button_module.css +53 -0
- package/dist/components/chips/@types/chip.d.ts +6 -0
- package/dist/components/chips/@types/chip.d.ts.map +1 -0
- package/dist/components/chips/@types/chip.js +7 -0
- package/dist/components/chips/chip.d.ts +32 -0
- package/dist/components/chips/chip.d.ts.map +1 -0
- package/dist/components/chips/chip.js +97 -0
- package/dist/components/chips/chip.module.css +425 -0
- package/dist/components/chips/chip.module.js +28 -0
- package/dist/components/chips/chip_module.css +319 -0
- package/dist/components/chips/index.js +2 -0
- package/dist/icons/check-icon.js +1 -0
- package/dist/icons/close-icon.d.ts.map +1 -1
- package/dist/icons/close-icon.js +21 -9
- package/dist/icons/icon-element.d.ts.map +1 -1
- package/dist/icons/icon-element.js +1 -4
- package/dist/icons/icons.module.css +8 -0
- package/dist/icons/icons_module.css +8 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -0
- package/dist/styles/components-vanilla.css +1 -1
- package/dist/styles/styles.css +1 -1
- package/package.json +18 -18
- package/src/components/button/@types/button.ts +1 -1
- package/src/components/button/button-intents.stories.tsx +2 -2
- package/src/components/button/button.module.css +107 -28
- package/src/components/chips/@types/chip.ts +7 -0
- package/src/components/chips/chip.module.css +425 -0
- package/src/components/chips/chip.stories.tsx +108 -0
- package/src/components/chips/chip.tsx +185 -0
- package/src/components/chips/index.ts +2 -0
- package/src/icons/check-icon.tsx +1 -1
- package/src/icons/close-icon.tsx +12 -11
- package/src/icons/icon-element.tsx +1 -4
- package/src/icons/icons.module.css +8 -0
- package/src/react.ts +1 -0
- package/src/styles/functional/colors.css +116 -107
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
4
|
+
import cx from 'classnames'
|
|
5
|
+
import type React from 'react'
|
|
6
|
+
|
|
7
|
+
import { CheckIcon } from '../../icons/check-icon.js'
|
|
8
|
+
import { IconButton } from '../button/icon-button.js'
|
|
9
|
+
import { CloseIcon } from '../../icons/close-icon.js'
|
|
10
|
+
import type { ChipIntent, ChipSize, ChipVariant } from './@types/chip.js'
|
|
11
|
+
import styles from './chip.module.css'
|
|
12
|
+
|
|
13
|
+
type AsButton = { asChild?: false } & React.ComponentPropsWithoutRef<'button'>
|
|
14
|
+
|
|
15
|
+
interface AsSlot {
|
|
16
|
+
asChild?: true
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ChipRefType<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref']
|
|
20
|
+
|
|
21
|
+
type ToggleEvent = React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>
|
|
22
|
+
type RemoveEvent = React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>
|
|
23
|
+
|
|
24
|
+
export type ChipProps<C extends React.ElementType = 'button'> = {
|
|
25
|
+
variant?: ChipVariant
|
|
26
|
+
intent?: ChipIntent
|
|
27
|
+
size?: ChipSize
|
|
28
|
+
selected?: boolean
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
startIcon?: React.ReactNode
|
|
31
|
+
endIcon?: React.ReactNode
|
|
32
|
+
selectedIcon?: React.ReactNode
|
|
33
|
+
removeLabel?: string
|
|
34
|
+
onToggle?: (selected: boolean, event: ToggleEvent) => void
|
|
35
|
+
onRemove?: (event: RemoveEvent) => void
|
|
36
|
+
className?: string
|
|
37
|
+
ref?: ChipRefType<C>
|
|
38
|
+
} & (AsButton | AsSlot) &
|
|
39
|
+
Omit<React.HTMLAttributes<HTMLElement>, 'onToggle'>
|
|
40
|
+
|
|
41
|
+
export const Chip = <C extends React.ElementType = 'button'>({
|
|
42
|
+
variant = 'assist',
|
|
43
|
+
intent = 'primary',
|
|
44
|
+
size = 'md',
|
|
45
|
+
selected = false,
|
|
46
|
+
disabled = false,
|
|
47
|
+
startIcon,
|
|
48
|
+
endIcon,
|
|
49
|
+
selectedIcon,
|
|
50
|
+
removeLabel = 'Remove chip',
|
|
51
|
+
onToggle,
|
|
52
|
+
onRemove,
|
|
53
|
+
className,
|
|
54
|
+
children,
|
|
55
|
+
asChild,
|
|
56
|
+
ref,
|
|
57
|
+
...rest
|
|
58
|
+
}: ChipProps<C>) => {
|
|
59
|
+
const { onClick, onKeyDown, role, tabIndex, ...restProps } = rest
|
|
60
|
+
const Comp: React.ElementType = asChild === true ? Slot : 'button'
|
|
61
|
+
const isSelectable = variant === 'selectable' || variant === 'selectable-removable'
|
|
62
|
+
const isRemovable = variant === 'removable' || variant === 'selectable-removable'
|
|
63
|
+
const isSelected = Boolean(selected)
|
|
64
|
+
|
|
65
|
+
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
|
66
|
+
if (disabled) {
|
|
67
|
+
event.preventDefault()
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (onClick) {
|
|
72
|
+
;(onClick as React.MouseEventHandler<HTMLElement>)(event)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isSelectable && onToggle) {
|
|
76
|
+
onToggle(!isSelected, event)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {
|
|
81
|
+
if (disabled) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if ((event.key === 'Enter' || event.key === ' ') && asChild === true) {
|
|
86
|
+
event.preventDefault()
|
|
87
|
+
if (onClick) {
|
|
88
|
+
;(onClick as React.MouseEventHandler<HTMLElement>)(event as unknown as React.MouseEvent<HTMLElement>)
|
|
89
|
+
}
|
|
90
|
+
if (isSelectable && onToggle) {
|
|
91
|
+
onToggle(!isSelected, event)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if ((event.key === 'Backspace' || event.key === 'Delete') && isRemovable && onRemove) {
|
|
96
|
+
event.preventDefault()
|
|
97
|
+
onRemove(event)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (onKeyDown) {
|
|
101
|
+
onKeyDown(event)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const handleRemoveClick = (event: React.MouseEvent<HTMLElement>) => {
|
|
106
|
+
if (disabled) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
event.stopPropagation()
|
|
110
|
+
if (onRemove) {
|
|
111
|
+
onRemove(event)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const handleRemoveKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {
|
|
116
|
+
if (disabled) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (event.key === 'Enter' || event.key === ' ' || event.key === 'Backspace' || event.key === 'Delete') {
|
|
121
|
+
event.preventDefault()
|
|
122
|
+
event.stopPropagation()
|
|
123
|
+
if (onRemove) {
|
|
124
|
+
onRemove(event)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const leadingIcon =
|
|
130
|
+
startIcon ?? (isSelectable && isSelected ? selectedIcon ?? <CheckIcon className={styles.icon} /> : null)
|
|
131
|
+
|
|
132
|
+
const trailingIcon = isRemovable ? (
|
|
133
|
+
<IconButton
|
|
134
|
+
role="button"
|
|
135
|
+
variant={isSelected ? 'filled-weak' : 'outlined'}
|
|
136
|
+
className={cx('remove', styles.remove, styles['end-icon'])}
|
|
137
|
+
tabIndex={disabled ? -1 : 0}
|
|
138
|
+
disabled={disabled}
|
|
139
|
+
aria-label={removeLabel}
|
|
140
|
+
onClick={handleRemoveClick}
|
|
141
|
+
onKeyDown={handleRemoveKeyDown}
|
|
142
|
+
>
|
|
143
|
+
<CloseIcon className={styles.icon} />
|
|
144
|
+
</IconButton>
|
|
145
|
+
) : (
|
|
146
|
+
endIcon
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
const appliedVariant = isSelected ? 'filled' : 'outlined'
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Comp
|
|
154
|
+
ref={ref}
|
|
155
|
+
type={asChild === true ? undefined : 'button'}
|
|
156
|
+
role={role ?? (asChild === true ? 'button' : undefined)}
|
|
157
|
+
tabIndex={disabled ? -1 : tabIndex ?? 0}
|
|
158
|
+
aria-disabled={disabled || undefined}
|
|
159
|
+
aria-pressed={isSelectable ? isSelected : undefined}
|
|
160
|
+
aria-selected={isSelectable ? isSelected : undefined}
|
|
161
|
+
className={cx(
|
|
162
|
+
'chip',
|
|
163
|
+
variant,
|
|
164
|
+
intent,
|
|
165
|
+
size,
|
|
166
|
+
{ selected: isSelected, disabled, removable: isRemovable },
|
|
167
|
+
styles.chip,
|
|
168
|
+
styles[appliedVariant],
|
|
169
|
+
styles[intent],
|
|
170
|
+
styles[size],
|
|
171
|
+
className
|
|
172
|
+
)}
|
|
173
|
+
disabled={asChild === true ? undefined : disabled}
|
|
174
|
+
onClick={handleClick}
|
|
175
|
+
onKeyDown={handleKeyDown}
|
|
176
|
+
{...restProps}
|
|
177
|
+
>
|
|
178
|
+
{leadingIcon != null && <span className={cx(styles.iconWrapper)}>{leadingIcon}</span>}
|
|
179
|
+
<span className={styles.label}>{children}</span>
|
|
180
|
+
{trailingIcon != null && <span className={cx(styles.iconWrapper)}>{trailingIcon}</span>}
|
|
181
|
+
</Comp>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
Chip.displayName = 'Chip'
|
package/src/icons/check-icon.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import styles from './icons.module.css'
|
|
|
10
10
|
|
|
11
11
|
export const CheckIcon = ({ className, svgClassName, ...rest }: IconProps): React.JSX.Element => {
|
|
12
12
|
const applied = cx(styles['fill-current'], svgClassName)
|
|
13
|
-
|
|
13
|
+
console.log('CheckIcon className:', className)
|
|
14
14
|
return (
|
|
15
15
|
<IconElement className={cx('check-icon', className)} {...rest}>
|
|
16
16
|
<svg
|
package/src/icons/close-icon.tsx
CHANGED
|
@@ -6,23 +6,24 @@ import styles from './icons.module.css'
|
|
|
6
6
|
import type { IconProps } from './types/icon.js'
|
|
7
7
|
|
|
8
8
|
export const CloseIcon = ({ className, svgClassName, ...rest }: IconProps): React.JSX.Element => {
|
|
9
|
-
const applied = cx(styles['
|
|
9
|
+
const applied = cx(styles['stroke-current'], svgClassName)
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
12
|
<IconElement className={cx('close-icon', className)} {...rest}>
|
|
13
|
-
<svg
|
|
13
|
+
<svg
|
|
14
14
|
className={applied}
|
|
15
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
16
16
|
focusable="false"
|
|
17
17
|
aria-hidden="true"
|
|
18
|
-
viewBox="0 0
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
viewBox="0 0 24 24" fill="none"
|
|
19
|
+
strokeWidth="2"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
strokeLinejoin="round"
|
|
22
|
+
>
|
|
23
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
|
24
|
+
<path d="M18 6l-12 12" />
|
|
25
|
+
<path d="M6 6l12 12" />
|
|
26
|
+
</svg>
|
|
26
27
|
</IconElement>
|
|
27
28
|
)
|
|
28
29
|
}
|
|
@@ -14,15 +14,12 @@ export interface IconElementProps extends React.ComponentProps<'div'> {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const IconElement = (props: IconElementProps): React.JSX.Element => {
|
|
17
|
-
const { className, children, width
|
|
17
|
+
const { className, children, width, height, menuItem = false, ...rest } = props
|
|
18
18
|
return (
|
|
19
19
|
<div
|
|
20
20
|
style={{
|
|
21
21
|
width,
|
|
22
22
|
height,
|
|
23
|
-
flex: `0 0 ${width}`,
|
|
24
|
-
alignItems: 'center',
|
|
25
|
-
justifyContent: 'center',
|
|
26
23
|
marginRight: menuItem != null && menuItem ? '1.2rem' : '0',
|
|
27
24
|
}}
|
|
28
25
|
className={cx(styles['element-root'], className)}
|
package/src/react.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './components/button/icon-button.js'
|
|
|
16
16
|
export * from './components/card/card.js'
|
|
17
17
|
export * from './components/container/container.js'
|
|
18
18
|
export * from './components/dropdown/dropdown.js'
|
|
19
|
+
export * from './components/chips/chip.js'
|
|
19
20
|
export * from './components/hamburger/hamburger.js'
|
|
20
21
|
export * from './components/forms/calendar.js'
|
|
21
22
|
export * from './components/forms/checkbox.js'
|