staffa 0.2.1 → 0.3.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.
Files changed (49) hide show
  1. package/README.md +169 -125
  2. package/dist/components/autocomplete.js +3 -2
  3. package/dist/components/box.js +2 -2
  4. package/dist/components/button.d.ts +11 -2
  5. package/dist/components/button.js +36 -8
  6. package/dist/components/buttonChooser.d.ts +4 -5
  7. package/dist/components/buttonChooser.js +2 -2
  8. package/dist/components/buttonGroup.js +0 -3
  9. package/dist/components/field.js +0 -3
  10. package/dist/components/main.d.ts +34 -9
  11. package/dist/components/main.js +187 -49
  12. package/dist/components/menu.d.ts +118 -0
  13. package/dist/components/menu.js +218 -0
  14. package/dist/components/tabs.d.ts +0 -2
  15. package/dist/components/tabs.js +6 -19
  16. package/dist/components/toast.d.ts +37 -0
  17. package/dist/components/toast.js +79 -0
  18. package/dist/components/tooltip.d.ts +32 -0
  19. package/dist/components/tooltip.js +130 -0
  20. package/dist/core.d.ts +1 -1
  21. package/dist/icons-helpers.d.ts +46 -0
  22. package/dist/icons-helpers.js +44 -0
  23. package/dist/icons.d.ts +1960 -0
  24. package/dist/icons.js +1972 -0
  25. package/dist/index.d.ts +11 -0
  26. package/dist/index.js +8 -0
  27. package/dist/staffa.esm.js +1 -1
  28. package/dist/theme.d.ts +1 -1
  29. package/dist/theme.js +114 -13
  30. package/package.json +10 -4
  31. package/src/components/autocomplete.ts +3 -2
  32. package/src/components/box.ts +2 -2
  33. package/src/components/button.ts +42 -10
  34. package/src/components/buttonChooser.ts +6 -7
  35. package/src/components/buttonGroup.ts +0 -3
  36. package/src/components/field.ts +0 -3
  37. package/src/components/main.ts +201 -45
  38. package/src/components/menu.ts +288 -0
  39. package/src/components/tabs.ts +6 -20
  40. package/src/components/toast.ts +115 -0
  41. package/src/components/tooltip.ts +139 -0
  42. package/src/core.ts +1 -1
  43. package/src/icons-helpers.ts +90 -0
  44. package/src/icons.ts +1977 -0
  45. package/src/index.ts +11 -0
  46. package/src/theme.ts +128 -18
  47. package/dist/components/modal.d.ts +0 -2
  48. package/dist/components/modal.js +0 -2
  49. package/dist/skye.esm.js +0 -1
@@ -0,0 +1,90 @@
1
+ import A from "aberdeen";
2
+
3
+ /** Stroke line-cap, as accepted by SVG's `stroke-linecap`. */
4
+ export type IconCap = "butt" | "round" | "square";
5
+ /** Stroke line-join, as accepted by SVG's `stroke-linejoin`. */
6
+ export type IconJoin = "arcs" | "bevel" | "miter" | "miter-clip" | "round";
7
+
8
+ /** Per-call overrides for a drawn icon. Anything omitted falls back to the
9
+ * module defaults (see {@link setDefaults}). */
10
+ export interface IconOptions {
11
+ /** Width & height, as a CSS length. A bare number is treated as pixels by
12
+ * SVG. Pass e.g. `"1em"` to scale the icon with the surrounding font. */
13
+ size?: number | string;
14
+ /** Stroke colour. Defaults to `"currentColor"`, so the icon inherits the
15
+ * current text colour. */
16
+ color?: string;
17
+ /** Stroke width in viewBox units (the viewBox is 24×24). */
18
+ strokeWidth?: number;
19
+ /** Stroke line-cap. */
20
+ cap?: IconCap;
21
+ /** Stroke line-join. */
22
+ join?: IconJoin;
23
+ /** Aberdeen attr/style string applied to the `<svg>` element. */
24
+ attrs?: string;
25
+ }
26
+
27
+ /** The resolved, always-present defaults backing {@link IconOptions}. */
28
+ export interface IconDefaults {
29
+ size: number | string;
30
+ color: string;
31
+ strokeWidth: number;
32
+ cap: IconCap;
33
+ join: IconJoin;
34
+ }
35
+
36
+ const defaults: IconDefaults = {
37
+ size: 24,
38
+ color: "currentColor",
39
+ strokeWidth: 2,
40
+ cap: "round",
41
+ join: "round",
42
+ };
43
+
44
+ /**
45
+ * Override the module-wide icon defaults. Affects every icon drawn afterwards.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { setDefaults } from "staffa/icons";
50
+ * setDefaults({ size: "1.25em", strokeWidth: 1.5 });
51
+ * ```
52
+ */
53
+ export function setDefaults(opts: Partial<IconDefaults>): void {
54
+ Object.assign(defaults, opts);
55
+ }
56
+
57
+ /**
58
+ * Draw a single icon: build one `<svg>` through Aberdeen (applying the
59
+ * {@link IconOptions} or the module defaults) and fill in its inner markup.
60
+ *
61
+ * This is the shared body behind every icon. {@link mk} hands it the icon's
62
+ * `inner` markup, so the per-icon closures stay tiny instead of each carrying
63
+ * a copy of this logic.
64
+ */
65
+ function drawIcon(inner: string, opts: IconOptions): void {
66
+ const size = opts.size ?? defaults.size;
67
+ const el = A(
68
+ 'svg.s-icon aria-hidden=true viewBox="0 0 24 24" fill=none',
69
+ "width=", size,
70
+ "height=", size,
71
+ "stroke=", opts.color ?? defaults.color,
72
+ "stroke-width=", opts.strokeWidth ?? defaults.strokeWidth,
73
+ "stroke-linecap=", opts.cap ?? defaults.cap,
74
+ "stroke-linejoin=", opts.join ?? defaults.join,
75
+ opts.attrs,
76
+ ) as SVGSVGElement;
77
+ // Drop the primitives in via innerHTML: setting it on the `<svg>` itself
78
+ // makes the parser put the children in the SVG namespace. (Aberdeen's
79
+ // `html=` builds them in the HTML namespace, leaving them non-rendering.)
80
+ el.innerHTML = inner;
81
+ }
82
+
83
+ /**
84
+ * Turn a piece of inner-SVG markup into an icon draw-function. The returned
85
+ * function emits a freshly-built `<svg>` into the current Aberdeen scope,
86
+ * applying the {@link IconOptions} (or the module defaults).
87
+ */
88
+ export function mk(inner: string): (opts?: IconOptions) => void {
89
+ return (opts: IconOptions = {}) => drawIcon(inner, opts);
90
+ }