@podoba/react 0.0.44 → 0.0.46

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podoba/react",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "type": "module",
5
5
  "description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
6
6
  "repository": {
@@ -28,8 +28,8 @@
28
28
  "typecheck": "tsc --build"
29
29
  },
30
30
  "dependencies": {
31
- "@podoba/tokens": "^0.0.44",
32
- "@podoba/tailwind": "^0.0.44",
31
+ "@podoba/tokens": "^0.0.46",
32
+ "@podoba/tailwind": "^0.0.46",
33
33
  "react-aria-components": "1.18.0",
34
34
  "class-variance-authority": "0.7.1",
35
35
  "clsx": "2.1.1",
@@ -1,51 +1,113 @@
1
1
  import type { ReactNode } from 'react'
2
2
  import { Label, Slider as RACSlider, type SliderProps as RACSliderProps, SliderThumb, SliderTrack } from 'react-aria-components'
3
3
 
4
+ export const SLIDER_SIZES = ['md', 'sm'] as const
5
+ export type SliderSize = (typeof SLIDER_SIZES)[number]
6
+ export const SLIDER_TONES = ['default', 'inverted'] as const
7
+ export type SliderTone = (typeof SLIDER_TONES)[number]
8
+
4
9
  /**
5
10
  * Slider — a draggable value selector (single value or a range when `value`/
6
11
  * `defaultValue` is a two-number array). Built on React Aria Components `Slider`
7
12
  * (keyboard support, RTL, ARIA). The filled portion is brand-green and each
8
- * thumb carries its current value above it (respects `formatOptions`).
13
+ * thumb carries its current value next to it (respects `formatOptions`).
14
+ * `orientation="vertical"` renders a 12rem tall track with the minimum at the
15
+ * bottom and the value label to the right of each thumb.
16
+ *
17
+ * `size="sm"` is the compact toolbar slider: one 24px row, the label kept for
18
+ * screen readers only and no value label (show your own readout beside it).
19
+ * `tone="inverted"` draws it for a dark surface such as a `bg-brand-primary` pill.
9
20
  */
10
- export type SliderProps<T extends number | number[]> = RACSliderProps<T> & {
11
- /** Visible label (required for accessibility). */
21
+ export type SliderProps<T extends number | number[]> = Omit<RACSliderProps<T>, 'className'> & {
22
+ /** Label (required for accessibility); visually hidden when `size="sm"`. */
12
23
  label: ReactNode
13
- /** Hide the value label above each thumb. */
24
+ /** Hide the value label next to each thumb (always hidden when `size="sm"`). */
14
25
  hideValue?: boolean
26
+ size?: SliderSize
27
+ tone?: SliderTone
28
+ /** Extra classes on the root, for layout such as a fixed width. */
29
+ className?: string
30
+ /**
31
+ * Drawn on the track between the rail and the fill, positioned absolutely
32
+ * against the track: e.g. a marked stretch of the range.
33
+ */
34
+ trackAdornment?: ReactNode
35
+ }
36
+
37
+ const RAIL = { md: { horizontal: 'h-1.5 w-full', vertical: 'h-full w-1.5' }, sm: { horizontal: 'h-1 w-full', vertical: 'h-full w-1' } }
38
+ const FILL = { md: { horizontal: 'h-1.5', vertical: 'w-1.5' }, sm: { horizontal: 'h-1', vertical: 'w-1' } }
39
+ const THUMB_SIZE = { md: 'h-4 w-4', sm: 'h-3.5 w-3.5' }
40
+ const THUMB_TONE = {
41
+ default: 'border-2 border-fg bg-surface data-[focus-visible]:ring-ring',
42
+ inverted: 'bg-fg-inverted data-[focus-visible]:ring-brand-green',
15
43
  }
44
+ const RAIL_TONE = { default: 'bg-surface-muted', inverted: 'bg-fg-inverted/30' }
45
+ const TEXT_TONE = { default: 'text-fg', inverted: 'text-fg-inverted' }
16
46
 
17
- export const Slider = <T extends number | number[]>({ label, hideValue, ...props }: SliderProps<T>) => (
18
- <RACSlider {...props} className="flex flex-col gap-1.5 data-[disabled]:opacity-50">
19
- <Label className="text-heading5 font-medium text-fg">{label}</Label>
20
- {/* mt-6 leaves room for the value label that sits above each thumb. */}
21
- <SliderTrack className="relative mt-6 flex h-6 w-full items-center">
22
- {({ state }) => {
23
- const start = state.values.length > 1 ? state.getThumbPercent(0) : 0
24
- const end = state.getThumbPercent(state.values.length - 1)
25
- return (
26
- <>
27
- <div className="h-1.5 w-full rounded-full bg-surface-muted" />
28
- <div
29
- className="absolute h-1.5 rounded-full bg-brand-green"
30
- style={{ left: `${start * 100}%`, width: `${(end - start) * 100}%` }}
31
- />
32
- {state.values.map((_, i) => (
33
- <SliderThumb
34
- // biome-ignore lint/suspicious/noArrayIndexKey: thumbs are positional and fixed-count
35
- key={i}
36
- index={i}
37
- className="h-4 w-4 rounded-full border-2 border-fg bg-surface outline-none transition-transform data-[dragging]:scale-110 data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring"
38
- >
39
- {hideValue ? null : (
40
- <span className="pointer-events-none absolute -top-6 left-1/2 -translate-x-1/2 whitespace-nowrap text-label font-medium tabular-nums text-fg">
41
- {state.getThumbValueLabel(i)}
42
- </span>
43
- )}
44
- </SliderThumb>
45
- ))}
46
- </>
47
- )
48
- }}
49
- </SliderTrack>
50
- </RACSlider>
51
- )
47
+ function trackClassName(size: SliderSize, vertical: boolean): string {
48
+ if (vertical) return 'relative flex h-48 w-6 justify-center'
49
+ // mt-6 leaves room for the value label that sits above each thumb.
50
+ return size === 'sm' ? 'relative flex h-6 w-full items-center' : 'relative mt-6 flex h-6 w-full items-center'
51
+ }
52
+
53
+ export const Slider = <T extends number | number[]>({
54
+ label,
55
+ hideValue,
56
+ size = 'md',
57
+ tone = 'default',
58
+ className,
59
+ trackAdornment,
60
+ ...props
61
+ }: SliderProps<T>) => {
62
+ const compact = size === 'sm'
63
+ const showValue = !hideValue && !compact
64
+ return (
65
+ <RACSlider
66
+ {...props}
67
+ className={`flex flex-col data-[disabled]:opacity-50${compact ? '' : ' gap-1.5'}${className ? ` ${className}` : ''}`}
68
+ >
69
+ <Label className={compact ? 'sr-only' : `text-heading5 font-medium ${TEXT_TONE[tone]}`}>{label}</Label>
70
+ <SliderTrack className={({ orientation }) => trackClassName(size, orientation === 'vertical')}>
71
+ {({ state }) => {
72
+ const isVertical = state.orientation === 'vertical'
73
+ const axis = isVertical ? 'vertical' : 'horizontal'
74
+ const start = state.values.length > 1 ? state.getThumbPercent(0) : 0
75
+ const end = state.getThumbPercent(state.values.length - 1)
76
+ return (
77
+ <>
78
+ <div className={`rounded-full ${RAIL_TONE[tone]} ${RAIL[size][axis]}`} />
79
+ {trackAdornment}
80
+ <div
81
+ className={`absolute rounded-full bg-brand-green ${FILL[size][axis]}`}
82
+ style={
83
+ isVertical
84
+ ? { bottom: `${start * 100}%`, height: `${(end - start) * 100}%` }
85
+ : { left: `${start * 100}%`, width: `${(end - start) * 100}%` }
86
+ }
87
+ />
88
+ {state.values.map((_, i) => (
89
+ <SliderThumb
90
+ // biome-ignore lint/suspicious/noArrayIndexKey: thumbs are positional and fixed-count
91
+ key={i}
92
+ index={i}
93
+ // React Aria positions the thumb along the track (`left` or, when
94
+ // vertical, `top`) with `translate(-50%, -50%)` but leaves the
95
+ // cross axis unset, so center it there ourselves.
96
+ className={`${isVertical ? 'left-1/2' : 'top-1/2'} ${THUMB_SIZE[size]} ${THUMB_TONE[tone]} rounded-full outline-none transition-transform data-[dragging]:scale-110 data-[focus-visible]:ring-2`}
97
+ >
98
+ {showValue ? (
99
+ <span
100
+ className={`pointer-events-none absolute whitespace-nowrap text-label font-medium tabular-nums ${TEXT_TONE[tone]} ${isVertical ? 'top-1/2 left-full ml-2 -translate-y-1/2' : '-top-6 left-1/2 -translate-x-1/2'}`}
101
+ >
102
+ {state.getThumbValueLabel(i)}
103
+ </span>
104
+ ) : null}
105
+ </SliderThumb>
106
+ ))}
107
+ </>
108
+ )
109
+ }}
110
+ </SliderTrack>
111
+ </RACSlider>
112
+ )
113
+ }