@solidrt/components 0.0.55 → 0.0.57

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/src/theme.ts CHANGED
@@ -76,6 +76,10 @@ export type Theme = {
76
76
  // borderWidth.focus by every focusable control. Defaults to text so it
77
77
  // stays visible on primary-filled controls.
78
78
  ring: string
79
+ // The text-selection highlight, drawn by the editable fields behind the
80
+ // selected glyphs; translucent so the text stays readable. Defaults to
81
+ // overlayPressed (a neutral scheme-aware tint that needs no color math).
82
+ selection: string
79
83
  }
80
84
  // Gaps and paddings, multiples of one base unit (sm 1x, md 2x, lg 4x,
81
85
  // xl 5x); read through space() where density should apply.
@@ -85,6 +89,13 @@ export type Theme = {
85
89
  // Tooltip), lg one step over (Card), full is the pill.
86
90
  radius: { sm: number; md: number; lg: number; full: number }
87
91
  borderWidth: { sm: number; focus: number }
92
+ // Motion durations (ms). Every built-in transition the components declare
93
+ // draws its timing here, so one theme edit retimes the whole package:
94
+ // fast is press/hover feedback, base the color/opacity fades (state
95
+ // changes, the theme cross-fade, popup enter/exit), slow the travel of a
96
+ // control's moving parts (switch knob, segmented indicator, progress
97
+ // fill). See motion.tsx; policy.motion gates them.
98
+ motion: { fast: number; base: number; slow: number }
88
99
  // Default extents of the components that have one: the panes and rails an
89
100
  // app lays its screens around, and the smallest sensible popup/track. Each
90
101
  // is a per-instance layout override away (listWidth, layout.width, ...);
@@ -110,7 +121,10 @@ export type Theme = {
110
121
  export type ThemeColor = string | [light: string, dark: string]
111
122
 
112
123
  export type ThemeDefinition = {
113
- color: { [K in Exclude<keyof Theme["color"], "ring">]: ThemeColor } & { ring?: ThemeColor }
124
+ color: { [K in Exclude<keyof Theme["color"], "ring" | "selection">]: ThemeColor } & {
125
+ ring?: ThemeColor
126
+ selection?: ThemeColor
127
+ }
114
128
  text?: {
115
129
  fontFamily?: string
116
130
  monoFamily?: string
@@ -130,6 +144,7 @@ export type ThemeDefinition = {
130
144
  // deriveRadius) or explicit steps. Default 8.
131
145
  radius?: number | Partial<Theme["radius"]>
132
146
  borderWidth?: Partial<Theme["borderWidth"]>
147
+ motion?: Partial<Theme["motion"]>
133
148
  size?: Partial<Theme["size"]>
134
149
  icons?: Theme["icons"]
135
150
  components?: Theme["components"]
@@ -149,6 +164,10 @@ function deriveRadius(base: number): Theme["radius"] {
149
164
  return { sm: Math.round(base / 2), md: base, lg: Math.round(base * 1.5), full: RADIUS_FULL }
150
165
  }
151
166
  const BORDER_WIDTH = { sm: 1, focus: 2 }
167
+ // The motion timing scale (ms): fast enough that feedback reads as
168
+ // immediate, base tuned so a state fade registers without dragging, slow
169
+ // long enough that a part's travel reads as movement rather than a flicker.
170
+ const MOTION = { fast: 100, base: 150, slow: 250 }
152
171
  const SIZE = { navRail: 72, navSidebar: 220, splitViewList: 320, menuMinWidth: 120, slider: 200 }
153
172
 
154
173
  // Line height and weight per role; body is the base text, label is body at
@@ -184,6 +203,7 @@ export function defineTheme(def: ThemeDefinition, scheme?: "light" | "dark"): Th
184
203
  } else color[k] = value
185
204
  }
186
205
  if (def.color.ring == null) color.ring = color.text
206
+ if (def.color.selection == null) color.selection = color.overlayPressed
187
207
  let base = def.text?.base ?? 14
188
208
  let ratio = def.text?.ratio ?? 1.26
189
209
  let role = (name: TextVariant): TextStyle => {
@@ -213,6 +233,7 @@ export function defineTheme(def: ThemeDefinition, scheme?: "light" | "dark"): Th
213
233
  radius:
214
234
  typeof def.radius === "number" ? deriveRadius(def.radius) : { ...deriveRadius(RADIUS_BASE), ...def.radius },
215
235
  borderWidth: { ...BORDER_WIDTH, ...def.borderWidth },
236
+ motion: { ...MOTION, ...def.motion },
216
237
  size: { ...SIZE, ...def.size },
217
238
  icons: def.icons ?? {},
218
239
  components: def.components ?? {},
@@ -253,6 +274,9 @@ const DEFAULT: ThemeDefinition = {
253
274
  // Feedback darkens on a light scheme and lightens on a dark one.
254
275
  overlayHover: ["rgba(0,0,0,0.08)", "rgba(255,255,255,0.08)"],
255
276
  overlayPressed: ["rgba(0,0,0,0.14)", "rgba(255,255,255,0.14)"],
277
+ // Primary (#547ebf) at a translucent strength: pale enough to read
278
+ // through on light, a touch stronger against the dark ground.
279
+ selection: ["rgba(84,126,191,0.30)", "rgba(84,126,191,0.40)"],
256
280
  },
257
281
  // base 14 and ratio 1.26 derive title 18 and heading 22; caption sits
258
282
  // one step under body but the ratio lands on 11, too small to read on a
package/src/tooltip.tsx CHANGED
@@ -5,7 +5,8 @@ import { policy } from "./policy"
5
5
  import { space } from "./spacing"
6
6
  import { typeStyle } from "./typography"
7
7
  import type { TransitionProps } from "./types"
8
- import { splitTransition, transitionEndFor } from "./types"
8
+ import { splitTransition, transitionEndFor, withTransitionDefaults } from "./types"
9
+ import { colorFade, popupFadeOut } from "./motion"
9
10
 
10
11
  export interface TooltipProps extends TransitionProps {
11
12
  // The tooltip body. A string/number renders as themed text; anything else
@@ -73,6 +74,9 @@ export function Tooltip(props: TooltipProps) {
73
74
  // share one build - reading the raw getter again would orphan native nodes.
74
75
  let content = children(() => props.content)
75
76
  let isText = () => typeof content() === "string" || typeof content() === "number"
77
+ // The fade is driven by the position write, not a mount-time `from`: the
78
+ // bubble parks offscreen until measured, so a `from` would play unseen;
79
+ // the exit fade plays when the bubble unmounts.
76
80
  return createPortal(
77
81
  <view
78
82
  ref={(n: { id: number }) => (bubble = n)}
@@ -87,21 +91,23 @@ export function Tooltip(props: TooltipProps) {
87
91
  paddingLeft={space("md")}
88
92
  paddingRight={space("md")}
89
93
  pointerEvents="none"
94
+ opacity={pos() ? 1 : 0}
95
+ transition={popupFadeOut()}
90
96
  >
91
97
  <d-rect
92
- transition={split().background}
98
+ transition={withTransitionDefaults(split().background, colorFade())}
93
99
  onTransitionEnd={transitionEndFor("background", props.onTransitionEnd)}
94
100
  color={theme.components.tooltip?.backgroundColor ?? theme.color.surfaceAlt}
95
101
  radius={theme.components.tooltip?.borderRadius ?? theme.radius.sm}
96
102
  />
97
103
  <Show when={isText()} fallback={content()}>
98
- <text color={theme.color.text} {...typeStyle("body")}>
104
+ <text transition={colorFade()} color={theme.color.text} {...typeStyle("body")}>
99
105
  {content()}
100
106
  </text>
101
107
  </Show>
102
108
  <d-rect
103
109
  drawStyle="stroke"
104
- transition={split().border}
110
+ transition={withTransitionDefaults(split().border, colorFade())}
105
111
  onTransitionEnd={transitionEndFor("border", props.onTransitionEnd)}
106
112
  color={theme.components.tooltip?.borderColor ?? theme.color.border}
107
113
  strokeWidth={theme.components.tooltip?.borderWidth ?? theme.borderWidth.sm}
package/src/types.ts CHANGED
@@ -21,9 +21,12 @@ import type {
21
21
  // component they would land on the root view, which has no paint, and be
22
22
  // silently ignored.
23
23
  //
24
- // Controls whose paint is their own (Switch knob, Slider thumb, Checkbox
25
- // mark, ...) take the view-level entries only for now; see
26
- // okf/backlog/component-transitions-internal-paint.md.
24
+ // Controls with a moving part of their own name it as an extra entry
25
+ // (Switch `knob`, SegmentedControl `indicator`, ProgressBar `fill`), routed
26
+ // by partTransition to the node owning it - with a built-in default from
27
+ // motion.tsx when the caller names nothing. Slider is the deliberate
28
+ // exception: its thumb and fill track the drag 1:1, and a transition would
29
+ // rubber-band it.
27
30
  export type TransitionViewProp =
28
31
  | "opacity"
29
32
  | "x"
@@ -84,9 +87,14 @@ const STYLE_TO_BORDER: Record<string, TransitionPropName> = {
84
87
  * Map a component declaration onto the three nodes a styled component
85
88
  * draws. `all`, a shorthand string and `stagger` apply to every node; named
86
89
  * entries go to the node owning the property. An entry for a node that is
87
- * not mounted (no background set) simply never animates.
90
+ * not mounted (no background set) simply never animates. `parts` lists the
91
+ * component's named moving parts, routed separately via partTransition, so
92
+ * their entries never leak onto the root view.
88
93
  */
89
- export function splitTransition<P extends string>(t: ComponentTransition<P> | undefined): SplitTransition {
94
+ export function splitTransition<P extends string>(
95
+ t: ComponentTransition<P> | undefined,
96
+ parts?: readonly string[],
97
+ ): SplitTransition {
90
98
  if (t == null || typeof t === "string") return { root: t, background: t, border: t }
91
99
  let root: Record<string, unknown> = {}
92
100
  let background: Record<string, unknown> = {}
@@ -99,7 +107,7 @@ export function splitTransition<P extends string>(t: ComponentTransition<P> | un
99
107
  } else if (key in STYLE_TO_BACKGROUND || key in STYLE_TO_BORDER) {
100
108
  if (key in STYLE_TO_BACKGROUND) background[STYLE_TO_BACKGROUND[key]!] = value
101
109
  if (key in STYLE_TO_BORDER) border[STYLE_TO_BORDER[key]!] = value
102
- } else {
110
+ } else if (!parts?.includes(key)) {
103
111
  root[key] = value
104
112
  }
105
113
  }
@@ -107,6 +115,66 @@ export function splitTransition<P extends string>(t: ComponentTransition<P> | un
107
115
  return { root: pick(root), background: pick(background), border: pick(border) }
108
116
  }
109
117
 
118
+ /**
119
+ * Fill a node's split declaration with the component's built-in transitions
120
+ * (motion.tsx) for the properties the caller left uncovered. A caller
121
+ * shorthand or `all` covers everything, so their intent wins wholesale;
122
+ * `transition={null}` suppresses the built-ins too; a named entry overrides
123
+ * the default for that property only.
124
+ */
125
+ export function withTransitionDefaults(
126
+ t: CoreTransitionProps["transition"],
127
+ defaults: Record<string, Transition | undefined> | undefined,
128
+ ): CoreTransitionProps["transition"] {
129
+ if (t === null || typeof t === "string") return t
130
+ if (t?.all !== undefined) return t
131
+ let filled: Record<string, unknown> | undefined
132
+ for (let key in defaults) {
133
+ let spec = defaults[key]
134
+ if (spec === undefined || (t && key in t)) continue
135
+ ;(filled ??= {})[key] = spec
136
+ }
137
+ if (!filled) return t
138
+ return { ...filled, ...t } as CoreTransitionProps["transition"]
139
+ }
140
+
141
+ /**
142
+ * The core declaration for a control's named moving part - a node owning
143
+ * one animatable property (Switch `knob` -> the knob's `x`). The caller's
144
+ * entry for the part (or `all`, or a shorthand string) retimes it, an
145
+ * absent one falls back to the control's built-in spec, and
146
+ * `transition={null}` suppresses that too.
147
+ */
148
+ export function partTransition<P extends string>(
149
+ t: ComponentTransition<P> | undefined,
150
+ part: string,
151
+ coreProp: TransitionPropName,
152
+ fallback: Transition | undefined,
153
+ ): CoreTransitionProps["transition"] {
154
+ let spec: Transition | undefined
155
+ if (t === null) spec = undefined
156
+ else if (typeof t === "string") spec = t
157
+ else if (t) spec = (t as Record<string, Transition | undefined>)[part] ?? t.all ?? fallback
158
+ else spec = fallback
159
+ return spec == null ? undefined : ({ [coreProp]: spec } as CoreTransitionProps["transition"])
160
+ }
161
+
162
+ /**
163
+ * Report a part's settled core property under the part's name. Filtered to
164
+ * the part's own property: the node may also run built-in fades (color),
165
+ * which have no name in the component vocabulary.
166
+ */
167
+ export function partTransitionEnd<P extends string>(
168
+ part: P,
169
+ coreProp: TransitionPropName,
170
+ handler: ((event: { property: P }) => void) | undefined,
171
+ ): ((event: TransitionEndEvent) => void) | undefined {
172
+ if (!handler) return undefined
173
+ return (e) => {
174
+ if (e.property === coreProp) handler({ property: part })
175
+ }
176
+ }
177
+
110
178
  /** Report a settled core property in the component vocabulary for the node it settled on. */
111
179
  export function transitionEndFor<P extends string>(
112
180
  node: "root" | "background" | "border",
package/src/view.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { LayoutProps, PointerProps } from "@solidrt/core"
2
2
  import type { StyleProps, TransitionProps } from "./types"
3
- import { splitTransition, transitionEndFor } from "./types"
3
+ import { splitTransition, transitionEndFor, withTransitionDefaults } from "./types"
4
+ import { colorFade } from "./motion"
4
5
 
5
6
  export interface ViewProps extends PointerProps, TransitionProps {
6
7
  children?: any
@@ -50,7 +51,7 @@ export function View(props: ViewProps) {
50
51
  >
51
52
  {hasBackground() ? (
52
53
  <d-rect
53
- transition={split().background}
54
+ transition={withTransitionDefaults(split().background, colorFade())}
54
55
  onTransitionEnd={transitionEndFor("background", props.onTransitionEnd)}
55
56
  color={props.style?.backgroundColor ?? "transparent"}
56
57
  radius={props.style?.borderRadius}
@@ -60,7 +61,7 @@ export function View(props: ViewProps) {
60
61
  {hasBorder() ? (
61
62
  <d-rect
62
63
  drawStyle="stroke"
63
- transition={split().border}
64
+ transition={withTransitionDefaults(split().border, colorFade())}
64
65
  onTransitionEnd={transitionEndFor("border", props.onTransitionEnd)}
65
66
  color={props.style?.borderColor ?? "transparent"}
66
67
  strokeWidth={props.style?.borderWidth}
package/src/window.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { LayoutProps, PointerProps } from "@solidrt/core"
2
2
  import type { StyleProps } from "./types"
3
+ import { colorFade } from "./motion"
3
4
 
4
5
  export interface WindowProps extends PointerProps {
5
6
  children?: any
@@ -31,7 +32,7 @@ export function Window(props: WindowProps) {
31
32
  pointerEvents={props.pointerEvents}
32
33
  >
33
34
  {props.style?.backgroundColor != null ? (
34
- <d-rect color={props.style.backgroundColor} />
35
+ <d-rect transition={colorFade()} color={props.style.backgroundColor} />
35
36
  ) : null}
36
37
  {props.children}
37
38
  </window>