@jongh/cli 1.1.0 → 1.1.1
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/index.js +1 -1
- package/package.json +16 -3
- package/.lintstagedrc.json +0 -4
- package/CHANGELOG.md +0 -7
- package/dist/components/Accordion/Accordion.tsx +0 -281
- package/dist/components/Accordion/index.tsx +0 -37
- package/dist/components/Accordion/useAccordionHeight.ts +0 -25
- package/dist/components/Avatar/Avatar.tsx +0 -18
- package/dist/components/Avatar/useAvatar.ts +0 -73
- package/dist/components/Button/index.tsx +0 -32
- package/dist/components/Primitive/index.tsx +0 -58
- package/dist/components/RovingIndex/RovingItem.tsx +0 -47
- package/dist/components/RovingIndex/RovingTabIndexRoot.tsx +0 -92
- package/dist/components/RovingIndex/index.ts +0 -3
- package/dist/components/RovingIndex/useRovingTabIndex.tsx +0 -76
- package/dist/components/Select/index.tsx +0 -231
- package/dist/components/Slider/index.tsx +0 -141
- package/dist/components/Slider/style.ts +0 -29
- package/dist/components/Tabs/Tab.tsx +0 -39
- package/dist/components/Tabs/TabContent.tsx +0 -62
- package/dist/components/Tabs/TabIndicator.tsx +0 -6
- package/dist/components/Tabs/TabList.tsx +0 -117
- package/dist/components/Tabs/index.ts +0 -43
- package/dist/components/Tabs/useRovingTabIndex.tsx +0 -171
- package/dist/components/Tabs/useTabContext.ts +0 -11
- package/dist/components/TagButton/TagButton.tsx +0 -75
- package/dist/components/TagButton/style.ts +0 -35
- package/dist/components/core/Polymorphic/index.ts +0 -26
- package/dist/components/index.ts +0 -5
- package/src/copyComponent.ts +0 -29
- package/src/getConfig.ts +0 -56
- package/src/index.ts +0 -46
- package/tsconfig.json +0 -14
- package/tsup.config.ts +0 -14
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useCallback, useRef, useState } from "react"
|
|
2
|
-
import { useControlledState } from "../../hooks/useControllableState"
|
|
3
|
-
import { RovingTabIndexProvider } from "./useRovingTabIndex"
|
|
4
|
-
import { Slot } from "@radix-ui/react-slot"
|
|
5
|
-
|
|
6
|
-
export const NODE_SELECTOR = "data-roving-tabindex-node"
|
|
7
|
-
const ROOT_SELECTOR = "data-roving-tabindex-root"
|
|
8
|
-
const NOT_FOCUSABLE_SELECTOR = "data-roving-tabindex-not-focusable"
|
|
9
|
-
const SELECTOR_ACTIVE = `:where([${NODE_SELECTOR}=true]):not(:where([${NOT_FOCUSABLE_SELECTOR}=true] *))`
|
|
10
|
-
|
|
11
|
-
type RovingTabIndexRootBaseProps = {
|
|
12
|
-
children: ReactNode | ReactNode[]
|
|
13
|
-
active?: string
|
|
14
|
-
setActive?: (value: string) => void
|
|
15
|
-
asChild?: boolean
|
|
16
|
-
dir?: "horizontal" | "vertical"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type RovingTabIndexRootProps = RovingTabIndexRootBaseProps
|
|
20
|
-
|
|
21
|
-
function onFocusFirst(candidates: HTMLElement[]) {
|
|
22
|
-
const previousFocus = document.activeElement
|
|
23
|
-
while (document.activeElement === previousFocus && candidates.length > 0) {
|
|
24
|
-
candidates.shift()?.focus()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const RovingTabIndexRoot = ({
|
|
29
|
-
children,
|
|
30
|
-
active,
|
|
31
|
-
setActive,
|
|
32
|
-
asChild,
|
|
33
|
-
dir = "horizontal",
|
|
34
|
-
...props
|
|
35
|
-
}: RovingTabIndexRootProps) => {
|
|
36
|
-
const [isShiftTabbing, setIsShiftTabbing] = useState(false)
|
|
37
|
-
|
|
38
|
-
const [value = null, setValue] = useControlledState({
|
|
39
|
-
prop: active,
|
|
40
|
-
onChange: setActive,
|
|
41
|
-
})
|
|
42
|
-
const rootRef = useRef<HTMLDivElement | null>(null)
|
|
43
|
-
const elementsRef = useRef<Map<string, HTMLElement>>(new Map())
|
|
44
|
-
const getOrderedItems = useCallback(() => {
|
|
45
|
-
if (!rootRef.current) return []
|
|
46
|
-
const activeElements = Array.from(
|
|
47
|
-
rootRef.current.querySelectorAll(SELECTOR_ACTIVE),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
return Array.from(elementsRef.current)
|
|
51
|
-
.sort(
|
|
52
|
-
(a, b) => activeElements.indexOf(a[1]) - activeElements.indexOf(b[1]),
|
|
53
|
-
)
|
|
54
|
-
.map(([value, element]) => ({ value, element }))
|
|
55
|
-
}, [])
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<RovingTabIndexProvider
|
|
59
|
-
setFocusableId={(value: string) => {
|
|
60
|
-
setValue(value)
|
|
61
|
-
}}
|
|
62
|
-
onShiftTab={() => {
|
|
63
|
-
setIsShiftTabbing(true)
|
|
64
|
-
}}
|
|
65
|
-
currentFocusedValue={value}
|
|
66
|
-
getOrderedItems={getOrderedItems}
|
|
67
|
-
elements={elementsRef}
|
|
68
|
-
dir={dir}
|
|
69
|
-
>
|
|
70
|
-
<Slot
|
|
71
|
-
{...{ [ROOT_SELECTOR]: true }}
|
|
72
|
-
tabIndex={isShiftTabbing ? -1 : 0}
|
|
73
|
-
onFocus={(e) => {
|
|
74
|
-
if (e.target !== e.currentTarget) return
|
|
75
|
-
if (isShiftTabbing) return
|
|
76
|
-
const orderedItems = getOrderedItems()
|
|
77
|
-
if (orderedItems.length === 0) return
|
|
78
|
-
const candidates = [
|
|
79
|
-
elementsRef.current.get(value ?? ""),
|
|
80
|
-
...orderedItems.map((i) => i.element),
|
|
81
|
-
].filter((element): element is HTMLElement => element != null)
|
|
82
|
-
onFocusFirst(candidates)
|
|
83
|
-
}}
|
|
84
|
-
onBlur={() => setIsShiftTabbing(false)}
|
|
85
|
-
ref={rootRef}
|
|
86
|
-
{...props}
|
|
87
|
-
>
|
|
88
|
-
{children}
|
|
89
|
-
</Slot>
|
|
90
|
-
</RovingTabIndexProvider>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FocusEvent,
|
|
3
|
-
MouseEvent,
|
|
4
|
-
KeyboardEvent,
|
|
5
|
-
ComponentPropsWithoutRef,
|
|
6
|
-
ElementType,
|
|
7
|
-
MutableRefObject,
|
|
8
|
-
} from "react"
|
|
9
|
-
import { createContext } from "../../hooks/createContext"
|
|
10
|
-
import { NODE_SELECTOR } from "./RovingTabIndexRoot"
|
|
11
|
-
|
|
12
|
-
export type RovingTabIndexItem = {
|
|
13
|
-
value: string
|
|
14
|
-
element: HTMLElement
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type RovingTabIndexContext = {
|
|
18
|
-
currentFocusedValue: string | null
|
|
19
|
-
setFocusableId: (id: string) => void
|
|
20
|
-
onShiftTab: () => void
|
|
21
|
-
getOrderedItems: () => RovingTabIndexItem[]
|
|
22
|
-
elements: MutableRefObject<Map<string, HTMLElement>>
|
|
23
|
-
dir?: "horizontal" | "vertical"
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const [RovingTabIndexProvider, useRovingTabIndexContext] =
|
|
27
|
-
createContext<RovingTabIndexContext>("rovingTabIndex")
|
|
28
|
-
|
|
29
|
-
export const useRovingTabIndex = (value: string) => {
|
|
30
|
-
const {
|
|
31
|
-
currentFocusedValue,
|
|
32
|
-
setFocusableId,
|
|
33
|
-
onShiftTab,
|
|
34
|
-
getOrderedItems,
|
|
35
|
-
elements,
|
|
36
|
-
dir,
|
|
37
|
-
} = useRovingTabIndexContext("rovingTabIndex")
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
getOrderedItems,
|
|
41
|
-
dir,
|
|
42
|
-
isFocusable: currentFocusedValue === value,
|
|
43
|
-
getRovingProps: <T extends ElementType>(
|
|
44
|
-
props?: ComponentPropsWithoutRef<T>,
|
|
45
|
-
) => ({
|
|
46
|
-
...props,
|
|
47
|
-
ref: (element: HTMLElement | null) => {
|
|
48
|
-
if (element) {
|
|
49
|
-
elements.current.set(value, element)
|
|
50
|
-
} else {
|
|
51
|
-
elements.current.delete(value)
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
onMouseDown: (e: MouseEvent) => {
|
|
55
|
-
props?.onMouseDown?.(e)
|
|
56
|
-
if (e.target !== e.currentTarget) return
|
|
57
|
-
setFocusableId(value)
|
|
58
|
-
},
|
|
59
|
-
onKeyDown: (e: KeyboardEvent) => {
|
|
60
|
-
props?.onKeyDown?.(e)
|
|
61
|
-
if (e.target !== e.currentTarget) return
|
|
62
|
-
if (e.shiftKey && e.key === "Tab") {
|
|
63
|
-
onShiftTab()
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
onFocus: (e: FocusEvent) => {
|
|
68
|
-
props?.onFocus?.(e)
|
|
69
|
-
if (e.target !== e.currentTarget) return
|
|
70
|
-
setFocusableId(value)
|
|
71
|
-
},
|
|
72
|
-
[NODE_SELECTOR]: true,
|
|
73
|
-
tabIndex: currentFocusedValue === value ? 0 : -1,
|
|
74
|
-
}),
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef,
|
|
3
|
-
type ComponentPropsWithoutRef,
|
|
4
|
-
type CSSProperties,
|
|
5
|
-
type ReactNode,
|
|
6
|
-
} from "react"
|
|
7
|
-
import { createContext } from "../../hooks/createContext"
|
|
8
|
-
import { useControlledState } from "../../hooks/useControllableState"
|
|
9
|
-
import { Slot } from "@radix-ui/react-slot"
|
|
10
|
-
import { RovingTabIndexRoot } from "../RovingIndex/RovingTabIndexRoot"
|
|
11
|
-
import {
|
|
12
|
-
autoUpdate,
|
|
13
|
-
flip,
|
|
14
|
-
offset,
|
|
15
|
-
size,
|
|
16
|
-
useFloating,
|
|
17
|
-
} from "@floating-ui/react-dom"
|
|
18
|
-
import {
|
|
19
|
-
useRovingTabIndex,
|
|
20
|
-
useRovingTabIndexContext,
|
|
21
|
-
} from "../RovingIndex/useRovingTabIndex"
|
|
22
|
-
import {
|
|
23
|
-
getNextFocusableId,
|
|
24
|
-
getPrevFocusableId,
|
|
25
|
-
} from "../../utils/getFocusableId"
|
|
26
|
-
import { composeRefs } from "../../hooks/useComposedRefs"
|
|
27
|
-
import { Primitive } from "src/components/Primitive"
|
|
28
|
-
|
|
29
|
-
const CONTEXT_NAME = "select"
|
|
30
|
-
|
|
31
|
-
interface SelectContext {
|
|
32
|
-
isOpen: boolean //option들의 열림/닫힘 여부
|
|
33
|
-
onOpenChange: (Open: boolean) => void
|
|
34
|
-
selected: string | null //option들 중 선택된 value
|
|
35
|
-
onSelectChange: (value: string) => void
|
|
36
|
-
floatingStyles?: CSSProperties
|
|
37
|
-
setFloating: (node: HTMLElement) => void
|
|
38
|
-
setReference: (node: HTMLElement | null) => void
|
|
39
|
-
dir: "horizontal" | "vertical"
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const [SelectContextProvider, useSelectContext] =
|
|
43
|
-
createContext<SelectContext>(CONTEXT_NAME)
|
|
44
|
-
|
|
45
|
-
export interface SelectProps extends ComponentPropsWithoutRef<"div"> {
|
|
46
|
-
isOpen?: boolean
|
|
47
|
-
onOpenChange?: (open: boolean) => void
|
|
48
|
-
defaultOpen?: boolean
|
|
49
|
-
selected?: string
|
|
50
|
-
onSelectChange?: (value: string) => void
|
|
51
|
-
defaultValue?: string
|
|
52
|
-
children: ReactNode
|
|
53
|
-
dir?: "horizontal" | "vertical"
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const SelectRoot = ({
|
|
57
|
-
isOpen,
|
|
58
|
-
onOpenChange,
|
|
59
|
-
defaultOpen,
|
|
60
|
-
selected,
|
|
61
|
-
onSelectChange,
|
|
62
|
-
defaultValue,
|
|
63
|
-
dir = "vertical",
|
|
64
|
-
children,
|
|
65
|
-
...props
|
|
66
|
-
}: SelectProps) => {
|
|
67
|
-
const [open = false, setIsOpen] = useControlledState({
|
|
68
|
-
prop: isOpen,
|
|
69
|
-
defaultProp: defaultOpen,
|
|
70
|
-
onChange: onOpenChange,
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const [selectedValue, setSelectedValue] = useControlledState({
|
|
74
|
-
prop: selected,
|
|
75
|
-
defaultProp: defaultValue,
|
|
76
|
-
onChange: onSelectChange,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
const { refs, floatingStyles } = useFloating({
|
|
80
|
-
strategy: "absolute",
|
|
81
|
-
open: open,
|
|
82
|
-
middleware: [
|
|
83
|
-
offset(), //trigger와 얼마나 떨어져있는지
|
|
84
|
-
flip(), //화면 밖으로 나가지 않도록
|
|
85
|
-
size({
|
|
86
|
-
apply({ elements, availableHeight }) {
|
|
87
|
-
elements.floating.style.maxHeight = `${availableHeight}px`
|
|
88
|
-
},
|
|
89
|
-
}),
|
|
90
|
-
],
|
|
91
|
-
whileElementsMounted: autoUpdate,
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<SelectContextProvider
|
|
96
|
-
isOpen={open}
|
|
97
|
-
onOpenChange={setIsOpen}
|
|
98
|
-
selected={selectedValue || null}
|
|
99
|
-
onSelectChange={setSelectedValue}
|
|
100
|
-
setFloating={refs.setFloating}
|
|
101
|
-
setReference={refs.setReference}
|
|
102
|
-
dir={dir}
|
|
103
|
-
floatingStyles={floatingStyles}
|
|
104
|
-
>
|
|
105
|
-
<RovingTabIndexRoot active={selectedValue} dir="vertical">
|
|
106
|
-
<div tabIndex={-1} {...props}>
|
|
107
|
-
{children}
|
|
108
|
-
</div>
|
|
109
|
-
</RovingTabIndexRoot>
|
|
110
|
-
</SelectContextProvider>
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface SelectTriggerProps
|
|
115
|
-
extends ComponentPropsWithoutRef<typeof Primitive.button> {
|
|
116
|
-
placeholder?: string
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const SelectTrigger = forwardRef<
|
|
120
|
-
React.ElementRef<typeof Primitive.button>,
|
|
121
|
-
SelectTriggerProps
|
|
122
|
-
>((props, ref) => {
|
|
123
|
-
const { getOrderedItems } = useRovingTabIndexContext("rovingTabIndex")
|
|
124
|
-
|
|
125
|
-
const { setReference, onOpenChange, isOpen, selected } =
|
|
126
|
-
useSelectContext(CONTEXT_NAME)
|
|
127
|
-
|
|
128
|
-
const displayText = selected || props.placeholder || ""
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<Primitive.button
|
|
132
|
-
ref={composeRefs((node) => setReference(node), ref)}
|
|
133
|
-
onClick={(e) => {
|
|
134
|
-
e.preventDefault()
|
|
135
|
-
onOpenChange(!isOpen)
|
|
136
|
-
props?.onClick?.(e)
|
|
137
|
-
}}
|
|
138
|
-
onKeyDown={(e) => {
|
|
139
|
-
setTimeout(() => {
|
|
140
|
-
if (e.key === "ArrowDown") {
|
|
141
|
-
onOpenChange(true)
|
|
142
|
-
getOrderedItems()[0]?.element.focus()
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
}}
|
|
146
|
-
{...props}
|
|
147
|
-
>
|
|
148
|
-
<span>{displayText}</span>
|
|
149
|
-
</Primitive.button>
|
|
150
|
-
)
|
|
151
|
-
})
|
|
152
|
-
export interface SelectPortalProps {
|
|
153
|
-
children: ReactNode
|
|
154
|
-
}
|
|
155
|
-
export const SelectPortal = ({ children, ...props }: SelectPortalProps) => {
|
|
156
|
-
const { isOpen, floatingStyles, setFloating } = useSelectContext(CONTEXT_NAME)
|
|
157
|
-
|
|
158
|
-
if (!isOpen) {
|
|
159
|
-
return null
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<Slot
|
|
164
|
-
style={floatingStyles}
|
|
165
|
-
ref={(node) => {
|
|
166
|
-
if (node instanceof HTMLElement) {
|
|
167
|
-
setFloating(node)
|
|
168
|
-
}
|
|
169
|
-
}}
|
|
170
|
-
{...props}
|
|
171
|
-
>
|
|
172
|
-
{children}
|
|
173
|
-
</Slot>
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export interface SelectItemProps
|
|
178
|
-
extends ComponentPropsWithoutRef<typeof Primitive.li> {
|
|
179
|
-
value: string
|
|
180
|
-
}
|
|
181
|
-
export const SelectItem = forwardRef<
|
|
182
|
-
React.ElementRef<typeof Primitive.li>,
|
|
183
|
-
SelectItemProps
|
|
184
|
-
>(({ children, value, asChild, ...props }, ref) => {
|
|
185
|
-
const { onSelectChange, onOpenChange, dir } = useSelectContext(CONTEXT_NAME)
|
|
186
|
-
const { getOrderedItems, getRovingProps } = useRovingTabIndex(value)
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
<Primitive.li
|
|
190
|
-
{...getRovingProps<typeof Primitive.li>({
|
|
191
|
-
onClick: () => {
|
|
192
|
-
onSelectChange?.(value)
|
|
193
|
-
onOpenChange(false)
|
|
194
|
-
},
|
|
195
|
-
onKeyDown: (e) => {
|
|
196
|
-
if (e.key === "Enter") {
|
|
197
|
-
onSelectChange?.(value)
|
|
198
|
-
onOpenChange(false)
|
|
199
|
-
}
|
|
200
|
-
const items = getOrderedItems()
|
|
201
|
-
let nextItem
|
|
202
|
-
if (dir === "horizontal") {
|
|
203
|
-
if (e.key === "ArrowRight") {
|
|
204
|
-
nextItem = getNextFocusableId(items, value)
|
|
205
|
-
} else if (e.key === "ArrowLeft") {
|
|
206
|
-
nextItem = getPrevFocusableId(items, value)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (dir === "vertical") {
|
|
210
|
-
if (e.key === "ArrowDown") {
|
|
211
|
-
nextItem = getNextFocusableId(items, value)
|
|
212
|
-
} else if (e.key === "ArrowUp") {
|
|
213
|
-
nextItem = getPrevFocusableId(items, value)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
nextItem?.element.focus()
|
|
217
|
-
},
|
|
218
|
-
})}
|
|
219
|
-
ref={ref}
|
|
220
|
-
{...props}
|
|
221
|
-
>
|
|
222
|
-
{children}
|
|
223
|
-
</Primitive.li>
|
|
224
|
-
)
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
export const Select = Object.assign(SelectRoot, {
|
|
228
|
-
Trigger: SelectTrigger,
|
|
229
|
-
Portal: SelectPortal,
|
|
230
|
-
Item: SelectItem,
|
|
231
|
-
})
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { useState, type ComponentPropsWithoutRef } from "react"
|
|
2
|
-
import { useControlledState } from "../../hooks/useControllableState"
|
|
3
|
-
import { createContext } from "../../hooks/createContext"
|
|
4
|
-
//TODO: props type 관련 정리 및 event composing 필요
|
|
5
|
-
const [SliderProvider, useSliderContext] = createContext<{
|
|
6
|
-
min: number
|
|
7
|
-
max: number
|
|
8
|
-
value: number
|
|
9
|
-
onChange: (value: number) => void
|
|
10
|
-
isDragging: boolean
|
|
11
|
-
onPointerDown: (e: React.PointerEvent) => void
|
|
12
|
-
onPointerMove: (e: React.PointerEvent) => void
|
|
13
|
-
onPointerUp: (e: React.PointerEvent) => void
|
|
14
|
-
}>("Slider")
|
|
15
|
-
|
|
16
|
-
type SliderRootProps = {
|
|
17
|
-
min: number
|
|
18
|
-
max: number
|
|
19
|
-
value: number
|
|
20
|
-
defaultValue?: number
|
|
21
|
-
onChange: (value: number) => void
|
|
22
|
-
children: React.ReactNode
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const getPercentage = (value: number, min: number, max: number) =>
|
|
26
|
-
((value - min) / (max - min)) * 100
|
|
27
|
-
|
|
28
|
-
const SliderRoot = ({
|
|
29
|
-
min = 0,
|
|
30
|
-
max = 100,
|
|
31
|
-
value,
|
|
32
|
-
onChange,
|
|
33
|
-
defaultValue,
|
|
34
|
-
children,
|
|
35
|
-
...props
|
|
36
|
-
}: SliderRootProps) => {
|
|
37
|
-
const [isDragging, setIsDragging] = useState(false)
|
|
38
|
-
|
|
39
|
-
const [innerValue = 0, setValue] = useControlledState({
|
|
40
|
-
prop: value,
|
|
41
|
-
defaultProp: defaultValue || min,
|
|
42
|
-
onChange,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const handlePointerDown = (e: React.PointerEvent) => {
|
|
46
|
-
e.preventDefault()
|
|
47
|
-
setIsDragging(true)
|
|
48
|
-
e.currentTarget.setPointerCapture(e.pointerId)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const handlePointerUp = (e: React.PointerEvent) => {
|
|
52
|
-
e.preventDefault()
|
|
53
|
-
setIsDragging(false)
|
|
54
|
-
e.currentTarget.releasePointerCapture(e.pointerId)
|
|
55
|
-
const { left, width } = e.currentTarget.getBoundingClientRect()
|
|
56
|
-
let percentage = (e.clientX - left) / width
|
|
57
|
-
percentage = Math.min(Math.max(percentage, 0), 1)
|
|
58
|
-
|
|
59
|
-
const newValue = min + percentage * (max - min)
|
|
60
|
-
setValue(newValue)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const handlePointerMove = (e: React.PointerEvent) => {
|
|
64
|
-
e.preventDefault()
|
|
65
|
-
if (!isDragging) return
|
|
66
|
-
|
|
67
|
-
const { left, width } = e.currentTarget.getBoundingClientRect()
|
|
68
|
-
let percentage = (e.clientX - left) / width
|
|
69
|
-
percentage = Math.min(Math.max(percentage, 0), 1)
|
|
70
|
-
const newValue = min + percentage * (max - min)
|
|
71
|
-
setValue(newValue)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<SliderProvider
|
|
76
|
-
min={min}
|
|
77
|
-
max={max}
|
|
78
|
-
value={innerValue}
|
|
79
|
-
onChange={setValue}
|
|
80
|
-
isDragging={isDragging}
|
|
81
|
-
onPointerDown={handlePointerDown}
|
|
82
|
-
onPointerMove={handlePointerMove}
|
|
83
|
-
onPointerUp={handlePointerUp}
|
|
84
|
-
>
|
|
85
|
-
<div
|
|
86
|
-
onPointerDown={handlePointerDown}
|
|
87
|
-
onPointerUp={handlePointerUp}
|
|
88
|
-
onPointerMove={handlePointerMove}
|
|
89
|
-
{...props}
|
|
90
|
-
>
|
|
91
|
-
{children}
|
|
92
|
-
</div>
|
|
93
|
-
</SliderProvider>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const SliderTrack = ({
|
|
98
|
-
children,
|
|
99
|
-
...props
|
|
100
|
-
}: {
|
|
101
|
-
children?: React.ReactNode
|
|
102
|
-
}) => {
|
|
103
|
-
return <span {...props}>{children}</span>
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const SliderRange = ({ ...props }: ComponentPropsWithoutRef<"span">) => {
|
|
107
|
-
const { min, max, value } = useSliderContext()
|
|
108
|
-
const percentage = getPercentage(value, min, max)
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<span
|
|
112
|
-
{...props}
|
|
113
|
-
style={{
|
|
114
|
-
width: `${percentage}%`,
|
|
115
|
-
}}
|
|
116
|
-
/>
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const SliderThumb = ({ ...props }: ComponentPropsWithoutRef<"span">) => {
|
|
121
|
-
const { min, max, value } = useSliderContext()
|
|
122
|
-
const percentage = getPercentage(value, min, max)
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<span
|
|
126
|
-
{...props}
|
|
127
|
-
style={{
|
|
128
|
-
position: "absolute",
|
|
129
|
-
left: `${percentage}%`,
|
|
130
|
-
transform: "translateX(-50%)",
|
|
131
|
-
}}
|
|
132
|
-
/>
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export const Slider = Object.assign(SliderRoot, {
|
|
137
|
-
Root: SliderRoot,
|
|
138
|
-
Track: SliderTrack,
|
|
139
|
-
Range: SliderRange,
|
|
140
|
-
Thumb: SliderThumb,
|
|
141
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Assign } from "../../types"
|
|
2
|
-
import { slider } from "@styled-system/recipes"
|
|
3
|
-
import type { ComponentProps, HTMLStyledProps } from "styled-system/types"
|
|
4
|
-
import { createStyleContext } from "../../utils/createStyleContext"
|
|
5
|
-
import { Slider } from "."
|
|
6
|
-
|
|
7
|
-
const { withProvider, withContext } = createStyleContext(slider)
|
|
8
|
-
|
|
9
|
-
export const Root = withProvider<
|
|
10
|
-
HTMLDivElement,
|
|
11
|
-
Assign<HTMLStyledProps<"div">, ComponentProps<typeof Slider.Root>>
|
|
12
|
-
>(Slider.Root, "root")
|
|
13
|
-
|
|
14
|
-
export const Track = withContext<
|
|
15
|
-
HTMLSpanElement,
|
|
16
|
-
Assign<HTMLStyledProps<"span">, ComponentProps<typeof Slider.Track>>
|
|
17
|
-
>(Slider.Track, "track")
|
|
18
|
-
|
|
19
|
-
export const Range = withContext<
|
|
20
|
-
HTMLSpanElement,
|
|
21
|
-
Assign<HTMLStyledProps<"span">, ComponentProps<typeof Slider.Range>>
|
|
22
|
-
>(Slider.Range, "range")
|
|
23
|
-
|
|
24
|
-
export const Thumb = withContext<
|
|
25
|
-
HTMLSpanElement,
|
|
26
|
-
Assign<HTMLStyledProps<"span">, ComponentProps<typeof Slider.Thumb>>
|
|
27
|
-
>(Slider.Thumb, "thumb")
|
|
28
|
-
|
|
29
|
-
export const StyledSlider = Object.assign(Root, { Track, Range, Thumb })
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useId, type ReactNode, type ForwardedRef } from "react"
|
|
2
|
-
import { useControlledState } from "../../hooks/useControllableState"
|
|
3
|
-
import { Slot } from "@radix-ui/react-slot"
|
|
4
|
-
import { TabProvider } from "./useTabContext"
|
|
5
|
-
|
|
6
|
-
export type TabProps = {
|
|
7
|
-
children?: ReactNode
|
|
8
|
-
selected?: string
|
|
9
|
-
defaultValue?: string
|
|
10
|
-
onSelect?: (value: string) => void
|
|
11
|
-
asChild?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const Tab = forwardRef(
|
|
15
|
-
(
|
|
16
|
-
{ children, selected, defaultValue, onSelect, asChild, ...props }: TabProps,
|
|
17
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
18
|
-
) => {
|
|
19
|
-
const Element = asChild ? Slot : "div"
|
|
20
|
-
|
|
21
|
-
const [value, setValue] = useControlledState({
|
|
22
|
-
prop: selected,
|
|
23
|
-
onChange: onSelect,
|
|
24
|
-
defaultProp: defaultValue,
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const onSelectItem = (value: string) => {
|
|
28
|
-
setValue(value)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<TabProvider selected={value} onSelect={onSelectItem} tabId={useId()}>
|
|
33
|
-
<Element ref={ref} {...props}>
|
|
34
|
-
{children}
|
|
35
|
-
</Element>
|
|
36
|
-
</TabProvider>
|
|
37
|
-
)
|
|
38
|
-
},
|
|
39
|
-
)
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from "react"
|
|
2
|
-
import { useTabContext } from "./useTabContext"
|
|
3
|
-
import { motion } from "framer-motion"
|
|
4
|
-
|
|
5
|
-
export interface TabContentProps {
|
|
6
|
-
children: ReactNode
|
|
7
|
-
value: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const tabContentVariant = {
|
|
11
|
-
active: {
|
|
12
|
-
display: "block",
|
|
13
|
-
transition: {
|
|
14
|
-
staggerChildren: 0.2,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
inactive: {
|
|
18
|
-
display: "none",
|
|
19
|
-
},
|
|
20
|
-
} as const
|
|
21
|
-
|
|
22
|
-
const cardVariant = {
|
|
23
|
-
active: {
|
|
24
|
-
opacity: 1,
|
|
25
|
-
x: 0,
|
|
26
|
-
transition: {
|
|
27
|
-
duration: 0.3,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
inactive: {
|
|
31
|
-
opacity: 0,
|
|
32
|
-
x: 10,
|
|
33
|
-
transition: {
|
|
34
|
-
duration: 0.3,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const TabContent = ({ children, value, ...props }: TabContentProps) => {
|
|
40
|
-
const { selected, tabId } = useTabContext("tab")
|
|
41
|
-
|
|
42
|
-
const isSelected = selected === value
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<motion.div
|
|
46
|
-
role="tabpanel"
|
|
47
|
-
tabIndex={0}
|
|
48
|
-
id={tabId + "-tabpanel-" + value}
|
|
49
|
-
data-state={isSelected ? "active" : "inactive"}
|
|
50
|
-
aria-labelledby={tabId + "-tabitem-" + value}
|
|
51
|
-
key={tabId + "-tabpanel-" + value}
|
|
52
|
-
variants={tabContentVariant}
|
|
53
|
-
animate={isSelected ? "active" : "inactive"}
|
|
54
|
-
initial="inactive"
|
|
55
|
-
{...props}
|
|
56
|
-
>
|
|
57
|
-
<motion.div key={value} variants={cardVariant}>
|
|
58
|
-
{isSelected && children}
|
|
59
|
-
</motion.div>
|
|
60
|
-
</motion.div>
|
|
61
|
-
)
|
|
62
|
-
}
|