@scalewing/react 0.2.0 → 0.3.0

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 (58) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +13 -2
  3. package/dist/components/Accordion.d.ts +8 -0
  4. package/dist/components/Accordion.js +14 -0
  5. package/dist/components/AppHeader.d.ts +5 -0
  6. package/dist/components/AppHeader.js +7 -0
  7. package/dist/components/Badge.d.ts +13 -0
  8. package/dist/components/Badge.js +7 -0
  9. package/dist/components/BarChart.d.ts +16 -0
  10. package/dist/components/BarChart.js +13 -0
  11. package/dist/components/Box.d.ts +1 -1
  12. package/dist/components/Button.d.ts +1 -1
  13. package/dist/components/Dialog.d.ts +8 -0
  14. package/dist/components/Dialog.js +36 -0
  15. package/dist/components/Field.d.ts +4 -1
  16. package/dist/components/Field.js +2 -2
  17. package/dist/components/Nav.d.ts +3 -0
  18. package/dist/components/Nav.js +7 -0
  19. package/dist/components/SegmentedControl.d.ts +19 -0
  20. package/dist/components/SegmentedControl.js +28 -0
  21. package/dist/components/Select.d.ts +17 -0
  22. package/dist/components/Select.js +107 -0
  23. package/dist/components/Split.d.ts +8 -0
  24. package/dist/components/Split.js +117 -0
  25. package/dist/components/Table.d.ts +32 -0
  26. package/dist/components/Table.js +24 -0
  27. package/dist/components/Text.d.ts +3 -3
  28. package/dist/components/Text.js +2 -1
  29. package/dist/components/Toast.d.ts +10 -0
  30. package/dist/components/Toast.js +61 -0
  31. package/dist/index.d.ts +17 -1
  32. package/dist/index.js +11 -0
  33. package/dist/palette/amber.css +21 -0
  34. package/dist/palette/capri.css +21 -0
  35. package/dist/palette/cerulean.css +21 -0
  36. package/dist/palette/cornflower.css +21 -0
  37. package/dist/palette/fuchsia.css +21 -0
  38. package/dist/palette/harvest.css +31 -0
  39. package/dist/palette/ink.css +21 -0
  40. package/dist/palette/mocha.css +31 -0
  41. package/dist/palette/navy.css +21 -0
  42. package/dist/palette/postcard.css +31 -0
  43. package/dist/palette/raspberry.css +21 -0
  44. package/dist/palette/sky.css +21 -0
  45. package/dist/palette/soft-blue.css +21 -0
  46. package/dist/palette/sunburst.css +31 -0
  47. package/dist/palette/synthwave.css +26 -0
  48. package/dist/palette/tangerine.css +21 -0
  49. package/dist/select-list.d.ts +7 -0
  50. package/dist/select-list.js +24 -0
  51. package/dist/split-size.d.ts +18 -0
  52. package/dist/split-size.js +94 -0
  53. package/dist/styles.css +1084 -12
  54. package/dist/theme/ThemeProvider.d.ts +4 -3
  55. package/dist/theme/ThemeProvider.js +8 -3
  56. package/dist/toast-travel.d.ts +16 -0
  57. package/dist/toast-travel.js +42 -0
  58. package/package.json +7 -3
@@ -0,0 +1,94 @@
1
+ import { spacingScale, splitScale } from '@scalewing/tokens';
2
+ export function cssLengthToPx(value, remPx = 16) {
3
+ const trimmed = value.trim();
4
+ if (trimmed.endsWith('rem')) {
5
+ const count = Number.parseFloat(trimmed);
6
+ return Number.isFinite(count) ? count * remPx : 0;
7
+ }
8
+ if (trimmed.endsWith('px')) {
9
+ const count = Number.parseFloat(trimmed);
10
+ return Number.isFinite(count) ? count : 0;
11
+ }
12
+ const count = Number.parseFloat(trimmed);
13
+ return Number.isFinite(count) ? count : 0;
14
+ }
15
+ export function readSplitMetrics(read, remPx = 16) {
16
+ return {
17
+ min: cssLengthToPx(read('--sw-split-min') || `${splitScale.min}rem`, remPx),
18
+ max: cssLengthToPx(read('--sw-split-max') || `${splitScale.max}rem`, remPx),
19
+ step: cssLengthToPx(read('--sw-space-4') || `${spacingScale[4]}px`, remPx),
20
+ defaultWidth: cssLengthToPx(read('--sw-split-size') || `${splitScale.size}rem`, remPx),
21
+ };
22
+ }
23
+ export function clampSplitSize(size, min, max) {
24
+ return Math.min(max, Math.max(min, size));
25
+ }
26
+ export function splitPercent(width, min, max) {
27
+ if (max <= min) {
28
+ return 0;
29
+ }
30
+ return Math.round(((clampSplitSize(width, min, max) - min) / (max - min)) * 100);
31
+ }
32
+ export function effectiveSplitMax(tokenMax, parentWidth, handleWidth, min) {
33
+ if (parentWidth <= 0) {
34
+ return tokenMax;
35
+ }
36
+ const room = parentWidth - handleWidth - min;
37
+ if (room < min) {
38
+ return min;
39
+ }
40
+ return Math.min(tokenMax, room);
41
+ }
42
+ export function applySplitDrag(start, deltaX, metrics) {
43
+ if (start.collapsed) {
44
+ if (deltaX <= 0) {
45
+ return start;
46
+ }
47
+ return {
48
+ collapsed: false,
49
+ width: clampSplitSize(metrics.min + deltaX, metrics.min, metrics.max),
50
+ };
51
+ }
52
+ const proposed = start.width + deltaX;
53
+ if (proposed < metrics.min) {
54
+ return { collapsed: true, width: start.width };
55
+ }
56
+ return {
57
+ collapsed: false,
58
+ width: clampSplitSize(proposed, metrics.min, metrics.max),
59
+ };
60
+ }
61
+ export function applySplitKey(key, start, metrics) {
62
+ if (key === 'Enter' || key === ' ') {
63
+ return { collapsed: !start.collapsed, width: start.width };
64
+ }
65
+ if (start.collapsed) {
66
+ if (key === 'ArrowRight') {
67
+ return { collapsed: false, width: start.width };
68
+ }
69
+ if (key === 'End') {
70
+ return { collapsed: false, width: metrics.max };
71
+ }
72
+ return null;
73
+ }
74
+ if (key === 'Home') {
75
+ return { collapsed: false, width: metrics.min };
76
+ }
77
+ if (key === 'End') {
78
+ return { collapsed: false, width: metrics.max };
79
+ }
80
+ if (key === 'ArrowRight') {
81
+ return {
82
+ collapsed: false,
83
+ width: clampSplitSize(start.width + metrics.step, metrics.min, metrics.max),
84
+ };
85
+ }
86
+ if (key === 'ArrowLeft') {
87
+ const next = start.width - metrics.step;
88
+ if (next < metrics.min) {
89
+ return { collapsed: true, width: start.width };
90
+ }
91
+ return { collapsed: false, width: next };
92
+ }
93
+ return null;
94
+ }