@uxf/styles 11.111.2 → 11.122.4
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/README.md +108 -43
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @uxf/styles
|
|
2
2
|
|
|
3
|
+
Low-level, framework-agnostic styling helpers: color mixing, CSS unit conversion, responsive media-query strings, CSS-in-JS property builders, an `sr-only` style object, and shared CSS unit types.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
Reach for `@uxf/styles` when you need small, pure helpers that produce **CSS values or media-query strings** in TypeScript/CSS-in-JS code (used internally by `@uxf/ui` and by app styling). Every helper is a plain function or object that returns a string/number/object.
|
|
8
|
+
|
|
9
|
+
It is **not** a component library and ships **no** stylesheet, global CSS, or Tailwind preset — only compiled JS and type declarations. It peer-depends on `@uxf/core` for a few utilities.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
yarn add @uxf/styles
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@uxf/core` is a required **peer dependency**; `color2k` is bundled as a regular dependency. There is no CSS to import and no provider to set up.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Import from the exact subpath (there is no package-root entry — see Gotchas):
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { rem } from "@uxf/styles/units/rem";
|
|
25
|
+
import { mqMin } from "@uxf/styles/responsive/mq-min";
|
|
26
|
+
|
|
27
|
+
const styles = {
|
|
28
|
+
padding: rem(16), // "1rem"
|
|
29
|
+
[`@media ${mqMin(768)}`]: {
|
|
30
|
+
// "(min-width: 48em)"
|
|
31
|
+
padding: rem(24), // "1.5rem"
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
3
36
|
## Color
|
|
4
37
|
|
|
5
38
|
### `shade` and `tint`
|
|
@@ -8,12 +41,13 @@
|
|
|
8
41
|
- returns HEX string with mix of provided color and specified amount of black (`shade`) or white (`tint`)
|
|
9
42
|
|
|
10
43
|
```ts
|
|
11
|
-
import { shade } from "@uxf/styles/
|
|
44
|
+
import { shade } from "@uxf/styles/color/shade";
|
|
12
45
|
|
|
13
46
|
const darker = shade("#f00", 0.1);
|
|
14
47
|
```
|
|
48
|
+
|
|
15
49
|
```ts
|
|
16
|
-
import { tint } from "@uxf/styles/
|
|
50
|
+
import { tint } from "@uxf/styles/color/tint";
|
|
17
51
|
|
|
18
52
|
const lighter = tint("#f00", 0.1);
|
|
19
53
|
```
|
|
@@ -22,7 +56,8 @@ const lighter = tint("#f00", 0.1);
|
|
|
22
56
|
|
|
23
57
|
### `srOnly`
|
|
24
58
|
|
|
25
|
-
-
|
|
59
|
+
- a JS object (React `CSSProperties`) with CSS to hide an element from all devices except screen readers
|
|
60
|
+
- apply it as an inline style / spread it — it is not a CSS class
|
|
26
61
|
|
|
27
62
|
```tsx
|
|
28
63
|
import { srOnly } from "@uxf/styles/mixins/sr-only";
|
|
@@ -34,7 +69,7 @@ const example = <div style={srOnly} />;
|
|
|
34
69
|
|
|
35
70
|
### `columnsToPercent`
|
|
36
71
|
|
|
37
|
-
- returns css `calc()` value with relative width of provided number of columns in provided total columns (
|
|
72
|
+
- returns css `calc()` value with relative width of provided number of columns in provided total columns (default is `12`) compensated by an optionally provided gutter (default `0`, in pixels)
|
|
38
73
|
|
|
39
74
|
```tsx
|
|
40
75
|
import { columnsToPercent } from "@uxf/styles/properties/columns-to-percent";
|
|
@@ -55,7 +90,8 @@ const example = encodedSvgUrl(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="
|
|
|
55
90
|
|
|
56
91
|
### `repeatGridColumns`
|
|
57
92
|
|
|
58
|
-
- returns css `repeat()` value of provided number of columns and size
|
|
93
|
+
- returns css `repeat()` value of provided number of columns and size (default `"1fr"`)
|
|
94
|
+
- returns `null` when `count` is falsy
|
|
59
95
|
|
|
60
96
|
```tsx
|
|
61
97
|
import { repeatGridColumns } from "@uxf/styles/properties/repeat-grid-columns";
|
|
@@ -66,133 +102,162 @@ const example = repeatGridColumns(6, "1fr"); /* returns "repeat(6, 1fr)" */
|
|
|
66
102
|
### `transition`
|
|
67
103
|
|
|
68
104
|
- returns css `transition` property for specified property or an array of properties
|
|
105
|
+
- accepts a `keyof CSSProperties` value (or array); defaults: `duration = 400` (ms), `easing = "ease-in-out"`
|
|
69
106
|
|
|
70
107
|
```tsx
|
|
71
108
|
import { transition } from "@uxf/styles/properties/transition";
|
|
72
109
|
|
|
73
110
|
const example = transition(["color", "transform"], 400, "ease-in-out");
|
|
74
|
-
/* returns "color 400ms ease-in-out, transform
|
|
111
|
+
/* returns "color 400ms ease-in-out, transform 400ms ease-in-out" */
|
|
75
112
|
```
|
|
76
113
|
|
|
77
114
|
## Responsive
|
|
78
115
|
|
|
79
|
-
### string media queries `mqBetween`, `mqHiDpi`, `mqMax`, `mqMin`
|
|
116
|
+
### string media queries: `mqBetween`, `mqHiDpi`, `mqMax`, `mqMin`
|
|
80
117
|
|
|
81
118
|
```tsx
|
|
82
119
|
import { mqBetween } from "@uxf/styles/responsive/mq-between";
|
|
83
120
|
|
|
84
|
-
const example = mqBetween(320, 480)
|
|
85
|
-
/* returns "(min-width: 20em and (max-width: 29.9375em)" */
|
|
121
|
+
const example = mqBetween(320, 480);
|
|
122
|
+
/* returns "(min-width: 20em) and (max-width: 29.9375em)" */
|
|
86
123
|
```
|
|
124
|
+
|
|
87
125
|
```tsx
|
|
88
126
|
import { mqHiDpi } from "@uxf/styles/responsive/mq-hidpi";
|
|
89
127
|
|
|
90
|
-
const example = mqHiDpi(3)
|
|
91
|
-
/* returns hidpi media query string for DPR 3.0 */
|
|
128
|
+
const example = mqHiDpi(3);
|
|
129
|
+
/* returns hidpi media query string for DPR 3.0 (default ratio is 2) */
|
|
92
130
|
```
|
|
93
131
|
|
|
94
|
-
### `window.matchMedia().matches` media queries `matchBetween`, `
|
|
132
|
+
### `window.matchMedia().matches` media queries: `matchBetween`, `matchHidpi`, `matchMax`, `matchMin`
|
|
133
|
+
|
|
134
|
+
- each returns a boolean; on the server (no `window`) they return `false`
|
|
95
135
|
|
|
96
136
|
```tsx
|
|
97
137
|
import { matchBetween } from "@uxf/styles/responsive/match-between";
|
|
98
138
|
|
|
99
|
-
const example = matchBetween(320, 480) /* returns boolean */
|
|
139
|
+
const example = matchBetween(320, 480); /* returns boolean */
|
|
100
140
|
```
|
|
141
|
+
|
|
101
142
|
```tsx
|
|
102
|
-
import {
|
|
143
|
+
import { matchHidpi } from "@uxf/styles/responsive/match-hidpi";
|
|
103
144
|
|
|
104
|
-
const example =
|
|
145
|
+
const example = matchHidpi(3); /* returns boolean */
|
|
105
146
|
```
|
|
106
147
|
|
|
107
148
|
## Units
|
|
108
149
|
|
|
109
150
|
### `em` and `rem`
|
|
110
151
|
|
|
111
|
-
- returns string
|
|
152
|
+
- returns string value divided by specified base (default `16`); `0` returns the string `"0"`
|
|
112
153
|
|
|
113
154
|
```tsx
|
|
114
155
|
import { em } from "@uxf/styles/units/em";
|
|
115
156
|
|
|
116
|
-
const example1 = em(320) /* returns "20em" */
|
|
117
|
-
const example2 = em(320, 10) /* returns "32em" */
|
|
157
|
+
const example1 = em(320); /* returns "20em" */
|
|
158
|
+
const example2 = em(320, 10); /* returns "32em" */
|
|
118
159
|
```
|
|
160
|
+
|
|
119
161
|
```tsx
|
|
120
162
|
import { rem } from "@uxf/styles/units/rem";
|
|
121
163
|
|
|
122
|
-
const example1 = rem(320) /* returns "20rem" */
|
|
123
|
-
const example2 = rem(320, 10) /* returns "32rem" */
|
|
164
|
+
const example1 = rem(320); /* returns "20rem" */
|
|
165
|
+
const example2 = rem(320, 10); /* returns "32rem" */
|
|
124
166
|
```
|
|
125
167
|
|
|
126
168
|
### `emToPx` and `remToPx`
|
|
127
169
|
|
|
128
|
-
- parse em or rem units to pixels (always returns `number`) by specified base (
|
|
170
|
+
- parse em or rem units to pixels (always returns `number`) by specified base (default `16`)
|
|
129
171
|
- the string `"0"` is also accepted and returns `0`
|
|
130
|
-
- throws an error for any other invalid input
|
|
172
|
+
- throws an error for any other invalid input
|
|
131
173
|
|
|
132
174
|
```tsx
|
|
133
175
|
import { emToPx } from "@uxf/styles/units/em-to-px";
|
|
134
176
|
|
|
135
|
-
const example1 = emToPx("20em")
|
|
136
|
-
const example2 = emToPx("20em", 10) /* 200 */
|
|
137
|
-
const example3 = emToPx("0")
|
|
177
|
+
const example1 = emToPx("20em"); /* 320 */
|
|
178
|
+
const example2 = emToPx("20em", 10); /* 200 */
|
|
179
|
+
const example3 = emToPx("0"); /* 0 */
|
|
138
180
|
// emToPx("20rem") — throws error: Invalid value
|
|
139
181
|
```
|
|
182
|
+
|
|
140
183
|
```tsx
|
|
141
184
|
import { remToPx } from "@uxf/styles/units/rem-to-px";
|
|
142
185
|
|
|
143
|
-
const example1 = remToPx("20rem")
|
|
144
|
-
const example2 = remToPx("20rem", 10) /* 200 */
|
|
145
|
-
const example3 = remToPx("0")
|
|
186
|
+
const example1 = remToPx("20rem"); /* 320 */
|
|
187
|
+
const example2 = remToPx("20rem", 10); /* 200 */
|
|
188
|
+
const example3 = remToPx("0"); /* 0 */
|
|
146
189
|
// remToPx("20%") — throws error: Invalid value
|
|
147
190
|
```
|
|
148
191
|
|
|
149
192
|
### `formatCssValue`
|
|
150
193
|
|
|
151
|
-
- returns normalized css value:
|
|
194
|
+
- returns a normalized css value: numbers become `rem` (or a plain string when `0` or `forceString`), non-empty strings pass through, anything else returns `null`
|
|
152
195
|
|
|
153
196
|
```tsx
|
|
154
197
|
import { formatCssValue } from "@uxf/styles/units/format-css-value";
|
|
155
198
|
|
|
156
|
-
const example1 = formatCssValue(0) /* returns "0" */
|
|
157
|
-
const example2 = formatCssValue(24) /* returns "1.5rem" */
|
|
158
|
-
const example3 = formatCssValue("100%") /* returns "100%" */
|
|
159
|
-
const example4 = formatCssValue(1, true) /* returns "1" */
|
|
199
|
+
const example1 = formatCssValue(0); /* returns "0" */
|
|
200
|
+
const example2 = formatCssValue(24); /* returns "1.5rem" */
|
|
201
|
+
const example3 = formatCssValue("100%"); /* returns "100%" */
|
|
202
|
+
const example4 = formatCssValue(1, true); /* returns "1" */
|
|
160
203
|
```
|
|
161
204
|
|
|
162
205
|
### `percent`
|
|
163
206
|
|
|
164
|
-
- returns float of percentage of provided number in provided max value (
|
|
207
|
+
- returns float of percentage of provided number in provided max value (default `100`) with provided precision (default `2`)
|
|
165
208
|
|
|
166
209
|
```tsx
|
|
167
210
|
import { percent } from "@uxf/styles/units/percent";
|
|
168
211
|
|
|
169
|
-
const example = percent(54.874, 80, 2) /* returns 68.59 */
|
|
212
|
+
const example = percent(54.874, 80, 2); /* returns 68.59 */
|
|
170
213
|
```
|
|
171
214
|
|
|
172
215
|
### `spacing`
|
|
173
216
|
|
|
174
|
-
> **Deprecated** —
|
|
217
|
+
> **Deprecated** — this function will be deleted in future versions.
|
|
175
218
|
|
|
176
|
-
- returns input multiplied by given factor (
|
|
219
|
+
- returns input multiplied by given factor (default `8`)
|
|
177
220
|
|
|
178
221
|
```tsx
|
|
179
222
|
import { spacing } from "@uxf/styles/units/spacing";
|
|
180
223
|
|
|
181
|
-
const example = spacing(4) /* returns 32 */
|
|
182
|
-
|
|
224
|
+
const example = spacing(4); /* returns 32 */
|
|
183
225
|
```
|
|
226
|
+
|
|
184
227
|
### `withUnit`
|
|
185
228
|
|
|
186
|
-
- returns literal of input with CSS unit
|
|
229
|
+
- returns literal of input with the given CSS unit
|
|
187
230
|
|
|
188
231
|
```tsx
|
|
189
232
|
import { withUnit } from "@uxf/styles/units/with-unit";
|
|
190
233
|
|
|
191
|
-
const example = withUnit(80, "vh") /* returns "80vh" */
|
|
234
|
+
const example = withUnit(80, "vh"); /* returns "80vh" */
|
|
192
235
|
```
|
|
193
236
|
|
|
194
237
|
## Types
|
|
195
238
|
|
|
196
|
-
|
|
197
|
-
|
|
239
|
+
Shared, typed CSS units and helper types, all exported from `@uxf/styles/types`:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import type { CssUnits, TransitionProperties } from "@uxf/styles/types";
|
|
243
|
+
```
|
|
198
244
|
|
|
245
|
+
| Type | Description |
|
|
246
|
+
| -------------------------- | ------------------------------------------------------------------- |
|
|
247
|
+
| `CssTimeUnits` | `"ms" \| "s"` |
|
|
248
|
+
| `CssAbsoluteLengthsUnits` | absolute length/angle units (`cm`, `mm`, `in`, `px`, `pt`, `pc`, `deg`, `rad`) |
|
|
249
|
+
| `CssRelativeLengthsUnits` | relative units (`em`, `ex`, `ch`, `rem`, `vw`, `vh`, `vmin`, `vmax`, `%`) |
|
|
250
|
+
| `CssUnits` | union of all of the above (accepted by `withUnit`) |
|
|
251
|
+
| `TransitionProperty` | `keyof CSSProperties` |
|
|
252
|
+
| `TransitionProperties` | `TransitionProperty \| TransitionProperty[]` (accepted by `transition`) |
|
|
253
|
+
|
|
254
|
+
## Gotchas
|
|
255
|
+
|
|
256
|
+
- **Deep imports only.** There is no package-root entry (no `index`), so a bare `import … from "@uxf/styles"` does not resolve. Always import from the exact subpath, e.g. `@uxf/styles/units/rem`.
|
|
257
|
+
- **No `exports` map.** Subpaths resolve by filesystem, so a path must match the on-disk file exactly — note it is `color` (singular) and `match-hidpi`.
|
|
258
|
+
- **Casing mismatch to watch.** The media-query string builder is `mqHiDpi` (capital `D`), but the boolean matcher is `matchHidpi` (lowercase `d`).
|
|
259
|
+
- **Ships no CSS.** Only compiled JS/JSX and `.d.ts` files are published (see `.npmignore`); there is no stylesheet, global CSS, or Tailwind preset to import.
|
|
260
|
+
- **`srOnly` is a JS object**, not a class — apply it via `style={srOnly}` or by spreading, not `className`.
|
|
261
|
+
- **`match*` helpers are client-only in effect.** They read `window.matchMedia` and return `false` on the server (guarded by `@uxf/core`'s `isBrowser`), so they are SSR-safe but never `true` during server render.
|
|
262
|
+
- **`emToPx` / `remToPx` throw** on any input that is not a matching `em` / `rem` string or the string `"0"`.
|
|
263
|
+
- **`@uxf/core` is a required peer dependency.**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/styles",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.122.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"color2k": "2.0.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@uxf/core": "11.
|
|
21
|
+
"@uxf/core": "11.114.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/react": "18.3.27",
|
|
25
|
-
"@uxf/core": "11.
|
|
25
|
+
"@uxf/core": "11.114.0",
|
|
26
26
|
"csstype": "3.2.3"
|
|
27
27
|
},
|
|
28
28
|
"author": "",
|