@xeplr/ui-utils 1.0.1 → 1.0.2

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.
@@ -71,5 +71,85 @@ export function getChartOptions(variantName, overrides) {
71
71
  return family ? { ...chart, fontFamily: family } : { ...chart };
72
72
  }
73
73
 
74
+ /**
75
+ * Theme → the CSS custom properties an input control reads.
76
+ *
77
+ * One control at a time, because the sections are separate: `input.text` and
78
+ * `input.select` are the same shape and need not hold the same values.
79
+ *
80
+ * Every edge is emitted on its own — border-top-width, -right, -bottom, -left
81
+ * — so "bottom rule only" is `{ border: { top: false, left: false, right:
82
+ * false, bottom: true } }` and not a fork of the stylesheet.
83
+ *
84
+ * <div style={inputStyleVars('text', overrides)}>…</div>
85
+ *
86
+ * @param {'text'|'select'|'number'|'date'} control
87
+ * @param {object} [overrides] consumer theme overrides
88
+ * @param {string} [variantName]
89
+ * @returns {object} { '--xeplr-input-text-…': value }
90
+ */
91
+ export function inputStyleVars(control, overrides, variantName) {
92
+ const theme = resolveTheme(overrides);
93
+ const variant = theme.themes[variantName] || theme.themes[theme.default];
94
+ const input = (variant && variant.input && variant.input[control]) || {};
95
+ const p = '--xeplr-input-' + control;
96
+ const border = input.border || {};
97
+ const font = input.font || {};
98
+ const label = input.label || {};
99
+ const ring = input.focusRing || {};
100
+ const invalid = input.invalid || {};
101
+
102
+ // An edge that is false is 0 — not "absent", which would fall through to the
103
+ // stylesheet's own default and quietly put the border back.
104
+ const edge = (on) => (on === false ? '0' : (border.width || '1px'));
105
+
106
+ const out = {
107
+ [p + '-gap']: input.gap,
108
+ [p + '-padding']: input.padding,
109
+ [p + '-bg']: input.background,
110
+ [p + '-color']: font.color,
111
+ [p + '-font-size']: font.size,
112
+ [p + '-placeholder']: font.placeholder,
113
+ [p + '-border-style']: border.style,
114
+ [p + '-border-color']: border.color,
115
+ [p + '-border-hover']: border.hover,
116
+ [p + '-border-focus']: border.focus,
117
+ [p + '-border-top']: edge(border.top),
118
+ [p + '-border-right']: edge(border.right),
119
+ [p + '-border-bottom']: edge(border.bottom),
120
+ [p + '-border-left']: edge(border.left),
121
+ [p + '-radius']: border.radius,
122
+ // The label carries the FULL Font block — the same shape
123
+ // @xeplr/ui-charts' type.js defines, so `underline` means the same thing
124
+ // on a field label as on a chart's. Every one of them is emitted, because
125
+ // a property the theme accepts and the stylesheet ignores is a setting
126
+ // that silently does nothing.
127
+ [p + '-label-family']: label.family,
128
+ [p + '-label-size']: label.size,
129
+ [p + '-label-weight']: label.weight,
130
+ [p + '-label-style']: label.style,
131
+ [p + '-label-variant']: label.variant,
132
+ [p + '-label-color']: label.color,
133
+ [p + '-label-line-height']: label.lineHeight,
134
+ [p + '-label-spacing']: label.letterSpacing,
135
+ [p + '-label-align']: label.align,
136
+ [p + '-label-transform']: label.transform,
137
+ [p + '-label-decoration']: label.decoration,
138
+ [p + '-label-opacity']: label.opacity,
139
+ [p + '-help-family']: (input.help || {}).family,
140
+ [p + '-help-size']: (input.help || {}).size,
141
+ [p + '-help-color']: (input.help || {}).color,
142
+ [p + '-help-style']: (input.help || {}).style,
143
+ [p + '-help-decoration']: (input.help || {}).decoration,
144
+ [p + '-ring']: ring.width,
145
+ [p + '-ring-color']: ring.color,
146
+ [p + '-invalid-color']: invalid.color,
147
+ [p + '-invalid-ring']: invalid.ring
148
+ };
149
+ // Undefined would render as the string "undefined" in a style object.
150
+ Object.keys(out).forEach((k) => { if (out[k] === undefined) delete out[k]; });
151
+ return out;
152
+ }
153
+
74
154
  export { defaultTheme };
75
155
  export default defaultTheme;