@olenbetong/synergi-react 0.6.46 → 0.7.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 (39) hide show
  1. package/dist/esm/ob.react.js +1 -17
  2. package/dist/esm/ob.react.min.css.map +1 -1
  3. package/dist/esm/ob.react.min.js +1 -1
  4. package/dist/esm/ob.react.min.js.map +4 -4
  5. package/dist/iife/ob.react.js +1 -14
  6. package/dist/iife/ob.react.min.css.map +1 -1
  7. package/dist/iife/ob.react.min.js +1 -1
  8. package/dist/iife/ob.react.min.js.map +4 -4
  9. package/dist/styles/styles.css.map +1 -1
  10. package/es/DateNavigator/index.js +2 -2
  11. package/es/Portal/index.js +1 -1
  12. package/es/index.d.ts +0 -1
  13. package/es/index.js +0 -1
  14. package/package.json +3 -4
  15. package/src/Checkbox/index.scss +78 -78
  16. package/src/Checkbox/index.tsx +62 -62
  17. package/src/ColorCard/index.scss +135 -135
  18. package/src/ColorCard/index.tsx +38 -38
  19. package/src/DateNavigator/index.scss +33 -33
  20. package/src/DateNavigator/index.tsx +66 -66
  21. package/src/LinkedCardList/index.scss +49 -49
  22. package/src/LinkedCardList/index.tsx +24 -24
  23. package/src/PageBanner/index.scss +71 -71
  24. package/src/PageBanner/index.tsx +41 -41
  25. package/src/Portal/index.tsx +24 -24
  26. package/src/ProgressBar/index.scss +76 -76
  27. package/src/ProgressBar/index.tsx +3 -3
  28. package/src/Sidebar/index.scss +41 -41
  29. package/src/Sidebar/index.tsx +107 -107
  30. package/src/Spinner/index.scss +45 -45
  31. package/src/Spinner/index.tsx +11 -11
  32. package/src/SplitContainer/index.scss +23 -23
  33. package/src/SplitContainer/index.tsx +222 -222
  34. package/src/ValueToggle/index.scss +37 -37
  35. package/src/ValueToggle/index.tsx +54 -54
  36. package/src/global.d.ts +1 -1
  37. package/src/index.ts +10 -11
  38. package/src/styles/_mixins.scss +16 -16
  39. package/src/useTranslation/index.ts +58 -58
@@ -2,40 +2,40 @@
2
2
  Hacky solution to sass output for some reason getting a zero-width space at the beginning, which breaks the first selector
3
3
  */
4
4
  .😖 {
5
- display: initial;
5
+ display: initial;
6
6
  }
7
7
 
8
8
  .ObSplitContainer-root {
9
- display: flex;
10
- flex-direction: column;
11
- height: 100%;
12
- width: 100%;
9
+ display: flex;
10
+ flex-direction: column;
11
+ height: 100%;
12
+ width: 100%;
13
13
 
14
- &.horizontal {
15
- flex-direction: row;
16
- }
14
+ &.horizontal {
15
+ flex-direction: row;
16
+ }
17
17
  }
18
18
 
19
19
  .ObSplitContainer-panel {
20
- overflow: hidden;
20
+ overflow: hidden;
21
21
  }
22
22
 
23
23
  .ObSplitContainer-divider {
24
- flex: 0 0 0.5rem;
25
- background-color: transparent;
26
- line-height: 0.75;
27
- cursor: ns-resize;
24
+ flex: 0 0 0.5rem;
25
+ background-color: transparent;
26
+ line-height: 0.75;
27
+ cursor: ns-resize;
28
28
 
29
- display: flex;
30
- align-items: center;
31
- justify-content: center;
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
32
 
33
- &:focus {
34
- background-color: rgba(0, 0, 0, 0.3);
35
- }
33
+ &:focus {
34
+ background-color: rgba(0, 0, 0, 0.3);
35
+ }
36
36
 
37
- .ObSplitContainer-root.horizontal > & {
38
- cursor: ew-resize;
39
- writing-mode: vertical-lr;
40
- }
37
+ .ObSplitContainer-root.horizontal > & {
38
+ cursor: ew-resize;
39
+ writing-mode: vertical-lr;
40
+ }
41
41
  }
@@ -5,271 +5,271 @@ import localforage from "localforage";
5
5
  import React, { Children, forwardRef, useEffect, useRef, useState } from "react";
6
6
 
7
7
  const settingsStore = localforage.createInstance({
8
- name: `AfSplitContainers.${af.userSession.login}`,
8
+ name: `AfSplitContainers.${af.userSession.login}`,
9
9
  });
10
10
 
11
11
  type SplitContainerSettings = {
12
- layoutVersion: string | number;
13
- fixedSize: number;
12
+ layoutVersion: string | number;
13
+ fixedSize: number;
14
14
  };
15
15
 
16
16
  const settingsCache: Record<string, SplitContainerSettings> = {};
17
17
 
18
18
  async function persistState(key: string, layoutVersion: string | number, fixedSize: number | null | undefined) {
19
- if (fixedSize != null) {
20
- let settings = {
21
- layoutVersion,
22
- fixedSize,
23
- };
24
-
25
- settingsCache[key] = settings;
26
- await settingsStore.setItem<SplitContainerSettings>(key, settings);
27
- }
19
+ if (fixedSize != null) {
20
+ let settings = {
21
+ layoutVersion,
22
+ fixedSize,
23
+ };
24
+
25
+ settingsCache[key] = settings;
26
+ await settingsStore.setItem<SplitContainerSettings>(key, settings);
27
+ }
28
28
  }
29
29
 
30
30
  async function getSettings(key: string, layoutVersion: string | number): Promise<number | null> {
31
- let settings = settingsCache[key] ?? (await settingsStore.getItem<SplitContainerSettings>(key));
31
+ let settings = settingsCache[key] ?? (await settingsStore.getItem<SplitContainerSettings>(key));
32
32
 
33
- if (settings && settings.layoutVersion === layoutVersion) {
34
- return settings.fixedSize;
35
- }
33
+ if (settings && settings.layoutVersion === layoutVersion) {
34
+ return settings.fixedSize;
35
+ }
36
36
 
37
- return null;
37
+ return null;
38
38
  }
39
39
 
40
40
  // Load all article grid layouts even if the grid is not mounted yet.
41
41
  // This ways the persisted state can be restored faster after the initial
42
42
  // page load.
43
43
  settingsStore.keys().then((keys) =>
44
- Promise.allSettled(
45
- keys
46
- .filter((key) => key.startsWith(af.article.id))
47
- .map((key) =>
48
- settingsStore.getItem<SplitContainerSettings>(key).then((settings) => {
49
- if (settings && !settingsCache[key]) {
50
- settingsCache[key] = settings;
51
- }
52
- })
53
- )
54
- )
44
+ Promise.allSettled(
45
+ keys
46
+ .filter((key) => key.startsWith(af.article.id))
47
+ .map((key) =>
48
+ settingsStore.getItem<SplitContainerSettings>(key).then((settings) => {
49
+ if (settings && !settingsCache[key]) {
50
+ settingsCache[key] = settings;
51
+ }
52
+ })
53
+ )
54
+ )
55
55
  );
56
56
 
57
57
  type DividerProps = {
58
- className?: string;
59
- direction: "horizontal" | "vertical";
60
- isDragging: boolean;
58
+ className?: string;
59
+ direction: "horizontal" | "vertical";
60
+ isDragging: boolean;
61
61
  };
62
62
 
63
63
  const Divider = forwardRef<HTMLDivElement, DividerProps>(function Divider(props: DividerProps, ref) {
64
- return (
65
- <div tabIndex={0} className={clsx("ObSplitContainer-divider", props.className)} ref={ref}>
66
- <span>•••</span>
67
- </div>
68
- );
64
+ return (
65
+ <div tabIndex={0} className={clsx("ObSplitContainer-divider", props.className)} ref={ref}>
66
+ <span>•••</span>
67
+ </div>
68
+ );
69
69
  });
70
70
 
71
71
  type SplitRootProps = React.HTMLProps<HTMLDivElement> & {
72
- className?: string;
73
- children: React.ReactNode;
74
- direction: "horizontal" | "vertical";
72
+ className?: string;
73
+ children: React.ReactNode;
74
+ direction: "horizontal" | "vertical";
75
75
  };
76
76
 
77
77
  function SplitRoot({ className, direction, ...props }: SplitRootProps) {
78
- return <div className={clsx(className, "ObSplitContainer-root", direction)} {...props} />;
78
+ return <div className={clsx(className, "ObSplitContainer-root", direction)} {...props} />;
79
79
  }
80
80
 
81
81
  type SplitPanelProps = {
82
- children: React.ReactNode;
83
- className?: string;
84
- style?: React.CSSProperties;
82
+ children: React.ReactNode;
83
+ className?: string;
84
+ style?: React.CSSProperties;
85
85
  } & (
86
- | {
87
- fixed: true;
88
- size: number;
89
- }
90
- | {
91
- fixed: false;
92
- size?: number;
93
- }
86
+ | {
87
+ fixed: true;
88
+ size: number;
89
+ }
90
+ | {
91
+ fixed: false;
92
+ size?: number;
93
+ }
94
94
  );
95
95
 
96
96
  function SplitPanel(props: SplitPanelProps) {
97
- let style = {
98
- flex: props.fixed ? `0 0 ${Math.floor(props.size)}px` : "1 1 100%",
99
- ...props.style,
100
- };
101
-
102
- return (
103
- <div className={clsx(props.className, "ObSplitContainer-panel")} style={style}>
104
- {props.children}
105
- </div>
106
- );
97
+ let style = {
98
+ flex: props.fixed ? `0 0 ${Math.floor(props.size)}px` : "1 1 100%",
99
+ ...props.style,
100
+ };
101
+
102
+ return (
103
+ <div className={clsx(props.className, "ObSplitContainer-panel")} style={style}>
104
+ {props.children}
105
+ </div>
106
+ );
107
107
  }
108
108
 
109
109
  export type SplitContainerProps = {
110
- className?: string;
111
- panelClassName?: string;
112
- children: React.ReactNode[];
113
- direction?: "horizontal" | "vertical";
114
- fixedPanel?: 1 | 2;
115
- defaultFixedSize?: number;
116
- /**
117
- * When the fixed size is persisted, changing the layoutVersion will force clients
118
- * to reset to the default value.
119
- */
120
- layoutVersion?: string | number;
121
- /**
122
- * If you set an id, the fixed size will be persisted, and restored after page load
123
- */
124
- id?: string;
110
+ className?: string;
111
+ panelClassName?: string;
112
+ children: React.ReactNode[];
113
+ direction?: "horizontal" | "vertical";
114
+ fixedPanel?: 1 | 2;
115
+ defaultFixedSize?: number;
116
+ /**
117
+ * When the fixed size is persisted, changing the layoutVersion will force clients
118
+ * to reset to the default value.
119
+ */
120
+ layoutVersion?: string | number;
121
+ /**
122
+ * If you set an id, the fixed size will be persisted, and restored after page load
123
+ */
124
+ id?: string;
125
125
  };
126
126
 
127
127
  export function SplitContainer({
128
- className,
129
- children,
130
- direction = "vertical",
131
- fixedPanel = 1,
132
- panelClassName,
133
- defaultFixedSize = 400,
134
- layoutVersion = 1,
135
- id,
128
+ className,
129
+ children,
130
+ direction = "vertical",
131
+ fixedPanel = 1,
132
+ panelClassName,
133
+ defaultFixedSize = 400,
134
+ layoutVersion = 1,
135
+ id,
136
136
  }: SplitContainerProps) {
137
- let [fixedSize, setFixedSize] = useState<number>(defaultFixedSize);
138
- let [isDragging, setIsDragging] = useState(false);
139
- let dividerRef = useRef<HTMLDivElement>(null);
140
-
141
- if (Children.count(children) !== 2) {
142
- throw Error("SplitContainer requires exactly 2 children");
143
- }
144
-
145
- function handleFixedSizeChanged(size: React.SetStateAction<number>) {
146
- setFixedSize((current) => {
147
- let newValue: number = typeof size === "function" ? size(current) : size;
148
-
149
- if (id) {
150
- let key = `${af.article.id}.${id}`;
151
- persistState(key, layoutVersion, newValue);
152
- }
153
-
154
- return newValue;
155
- });
156
- }
157
-
158
- useEffect(() => {
159
- if (id) {
160
- let key = `${af.article.id}.${id}`;
161
-
162
- getSettings(key, layoutVersion).then((data: number | null) => {
163
- if (data) {
164
- // Persisted state exists, and matches the current layout version,
165
- // so restore the state.
166
- setFixedSize(data);
167
-
168
- return Promise.resolve();
169
- }
170
- });
171
- }
172
- }, [id, layoutVersion]);
173
-
174
- let childrenArray = Children.toArray(children);
175
-
176
- useEffect(() => {
177
- let divider = dividerRef.current;
178
- if (divider) {
179
- let initialPosition: { clientX: number; clientY: number; size: number } = {
180
- clientX: 0,
181
- clientY: 0,
182
- size: 0,
183
- };
184
- let movingPanel: HTMLElement = (
185
- fixedPanel === 1 ? divider.previousElementSibling : divider.nextElementSibling
186
- ) as HTMLElement;
187
-
188
- function getNewSize(event: PointerEvent) {
189
- let deltaSize =
190
- direction === "horizontal"
191
- ? event.clientX - initialPosition.clientX
192
- : event.clientY - initialPosition.clientY;
193
-
194
- deltaSize *= fixedPanel === 1 ? -1 : 1;
195
-
196
- return initialPosition.size - deltaSize;
197
- }
198
-
199
- function handlePointerUp(event: PointerEvent) {
200
- let newSize = getNewSize(event);
201
- handleFixedSizeChanged(newSize);
202
- setIsDragging(false);
203
-
204
- movingPanel.style.flex = `0 0 ${Math.floor(newSize)}px`;
205
- window.removeEventListener("pointermove", handlePointerMove);
206
- }
207
-
208
- function handlePointerMove(event: PointerEvent) {
209
- event.preventDefault();
210
-
211
- let newSize = getNewSize(event);
212
- movingPanel.style.flex = `0 0 ${newSize}px`;
213
- }
214
-
215
- function handlePointerDown(event: PointerEvent) {
216
- setIsDragging(true);
217
-
218
- let rect = movingPanel.getBoundingClientRect();
219
- let size = direction === "horizontal" ? rect.width : rect.height;
220
- initialPosition = {
221
- clientX: event.clientX,
222
- clientY: event.clientY,
223
- size,
224
- };
225
-
226
- window.addEventListener("pointermove", handlePointerMove);
227
- window.addEventListener("pointerup", handlePointerUp, { once: true });
228
- }
229
-
230
- function handleKeyDown(event: KeyboardEvent) {
231
- let reduce: boolean = true;
232
- let shouldHandle: boolean = false;
233
- if (!event.altKey && !event.ctrlKey && !event.metaKey) {
234
- if (direction === "horizontal" && ["ArrowLeft", "ArrowRight"].includes(event.key)) {
235
- shouldHandle = true;
236
- reduce =
237
- (fixedPanel === 1 && event.key === "ArrowLeft") || (fixedPanel === 2 && event.key === "ArrowRight");
238
- } else if (direction === "vertical" && ["ArrowUp", "ArrowDown"].includes(event.key)) {
239
- shouldHandle = true;
240
- reduce = (fixedPanel === 1 && event.key === "ArrowUp") || (fixedPanel === 2 && event.key === "ArrowDown");
241
- }
242
- }
243
-
244
- if (shouldHandle) {
245
- event.preventDefault();
246
- event.stopPropagation();
247
-
248
- let delta = event.shiftKey ? 25 : 5;
249
-
250
- handleFixedSizeChanged((size) => size + (reduce ? -delta : delta));
251
- }
252
- }
253
-
254
- divider.addEventListener("pointerdown", handlePointerDown);
255
- divider.addEventListener("keydown", handleKeyDown);
256
-
257
- return () => {
258
- divider?.removeEventListener("pointerdown", handlePointerDown);
259
- divider?.removeEventListener("keydown", handleKeyDown);
260
- };
261
- }
262
- }, [direction, fixedPanel]);
263
-
264
- return (
265
- <SplitRoot direction={direction} className={className}>
266
- <SplitPanel className={panelClassName} fixed={fixedPanel === 1} size={fixedSize}>
267
- {childrenArray[0]}
268
- </SplitPanel>
269
- <Divider ref={dividerRef} direction={direction} isDragging={isDragging} />
270
- <SplitPanel className={panelClassName} fixed={fixedPanel === 2} size={fixedSize}>
271
- {childrenArray[1]}
272
- </SplitPanel>
273
- </SplitRoot>
274
- );
137
+ let [fixedSize, setFixedSize] = useState<number>(defaultFixedSize);
138
+ let [isDragging, setIsDragging] = useState(false);
139
+ let dividerRef = useRef<HTMLDivElement>(null);
140
+
141
+ if (Children.count(children) !== 2) {
142
+ throw Error("SplitContainer requires exactly 2 children");
143
+ }
144
+
145
+ function handleFixedSizeChanged(size: React.SetStateAction<number>) {
146
+ setFixedSize((current) => {
147
+ let newValue: number = typeof size === "function" ? size(current) : size;
148
+
149
+ if (id) {
150
+ let key = `${af.article.id}.${id}`;
151
+ persistState(key, layoutVersion, newValue);
152
+ }
153
+
154
+ return newValue;
155
+ });
156
+ }
157
+
158
+ useEffect(() => {
159
+ if (id) {
160
+ let key = `${af.article.id}.${id}`;
161
+
162
+ getSettings(key, layoutVersion).then((data: number | null) => {
163
+ if (data) {
164
+ // Persisted state exists, and matches the current layout version,
165
+ // so restore the state.
166
+ setFixedSize(data);
167
+
168
+ return Promise.resolve();
169
+ }
170
+ });
171
+ }
172
+ }, [id, layoutVersion]);
173
+
174
+ let childrenArray = Children.toArray(children);
175
+
176
+ useEffect(() => {
177
+ let divider = dividerRef.current;
178
+ if (divider) {
179
+ let initialPosition: { clientX: number; clientY: number; size: number } = {
180
+ clientX: 0,
181
+ clientY: 0,
182
+ size: 0,
183
+ };
184
+ let movingPanel: HTMLElement = (
185
+ fixedPanel === 1 ? divider.previousElementSibling : divider.nextElementSibling
186
+ ) as HTMLElement;
187
+
188
+ function getNewSize(event: PointerEvent) {
189
+ let deltaSize =
190
+ direction === "horizontal"
191
+ ? event.clientX - initialPosition.clientX
192
+ : event.clientY - initialPosition.clientY;
193
+
194
+ deltaSize *= fixedPanel === 1 ? -1 : 1;
195
+
196
+ return initialPosition.size - deltaSize;
197
+ }
198
+
199
+ function handlePointerUp(event: PointerEvent) {
200
+ let newSize = getNewSize(event);
201
+ handleFixedSizeChanged(newSize);
202
+ setIsDragging(false);
203
+
204
+ movingPanel.style.flex = `0 0 ${Math.floor(newSize)}px`;
205
+ window.removeEventListener("pointermove", handlePointerMove);
206
+ }
207
+
208
+ function handlePointerMove(event: PointerEvent) {
209
+ event.preventDefault();
210
+
211
+ let newSize = getNewSize(event);
212
+ movingPanel.style.flex = `0 0 ${newSize}px`;
213
+ }
214
+
215
+ function handlePointerDown(event: PointerEvent) {
216
+ setIsDragging(true);
217
+
218
+ let rect = movingPanel.getBoundingClientRect();
219
+ let size = direction === "horizontal" ? rect.width : rect.height;
220
+ initialPosition = {
221
+ clientX: event.clientX,
222
+ clientY: event.clientY,
223
+ size,
224
+ };
225
+
226
+ window.addEventListener("pointermove", handlePointerMove);
227
+ window.addEventListener("pointerup", handlePointerUp, { once: true });
228
+ }
229
+
230
+ function handleKeyDown(event: KeyboardEvent) {
231
+ let reduce: boolean = true;
232
+ let shouldHandle: boolean = false;
233
+ if (!event.altKey && !event.ctrlKey && !event.metaKey) {
234
+ if (direction === "horizontal" && ["ArrowLeft", "ArrowRight"].includes(event.key)) {
235
+ shouldHandle = true;
236
+ reduce =
237
+ (fixedPanel === 1 && event.key === "ArrowLeft") || (fixedPanel === 2 && event.key === "ArrowRight");
238
+ } else if (direction === "vertical" && ["ArrowUp", "ArrowDown"].includes(event.key)) {
239
+ shouldHandle = true;
240
+ reduce = (fixedPanel === 1 && event.key === "ArrowUp") || (fixedPanel === 2 && event.key === "ArrowDown");
241
+ }
242
+ }
243
+
244
+ if (shouldHandle) {
245
+ event.preventDefault();
246
+ event.stopPropagation();
247
+
248
+ let delta = event.shiftKey ? 25 : 5;
249
+
250
+ handleFixedSizeChanged((size) => size + (reduce ? -delta : delta));
251
+ }
252
+ }
253
+
254
+ divider.addEventListener("pointerdown", handlePointerDown);
255
+ divider.addEventListener("keydown", handleKeyDown);
256
+
257
+ return () => {
258
+ divider?.removeEventListener("pointerdown", handlePointerDown);
259
+ divider?.removeEventListener("keydown", handleKeyDown);
260
+ };
261
+ }
262
+ }, [direction, fixedPanel]);
263
+
264
+ return (
265
+ <SplitRoot direction={direction} className={className}>
266
+ <SplitPanel className={panelClassName} fixed={fixedPanel === 1} size={fixedSize}>
267
+ {childrenArray[0]}
268
+ </SplitPanel>
269
+ <Divider ref={dividerRef} direction={direction} isDragging={isDragging} />
270
+ <SplitPanel className={panelClassName} fixed={fixedPanel === 2} size={fixedSize}>
271
+ {childrenArray[1]}
272
+ </SplitPanel>
273
+ </SplitRoot>
274
+ );
275
275
  }
@@ -1,50 +1,50 @@
1
1
  @import "../styles/variables";
2
2
 
3
3
  .ObValueToggle-root {
4
- display: flex;
5
- align-items: center;
4
+ display: flex;
5
+ align-items: center;
6
6
  }
7
7
 
8
8
  .ObValueToggle-option {
9
- margin-bottom: 0;
9
+ margin-bottom: 0;
10
10
  }
11
11
 
12
12
  .ObValueToggle-label {
13
- cursor: pointer;
14
- font-size: 0.8em;
15
- margin: 0 0.2em;
16
- padding: 0.3em 0.5em;
17
- text-transform: uppercase;
18
-
19
- &:hover {
20
- background: #ccc;
21
- }
22
-
23
- .ObValueToggle-input:checked + & {
24
- --color-bg: var(--brand-dark);
25
- background-color: #666;
26
- background-color: var(--color-bg);
27
- cursor: default;
28
- color: white;
29
- }
30
-
31
- .ObValueToggle-input:checked:focus-within + & {
32
- --color-bg: var(--brand-light);
33
- }
34
-
35
- .ObValueToggle-input:checked:hover + & {
36
- background-color: #666;
37
- background-color: var(--color-bg);
38
- }
13
+ cursor: pointer;
14
+ font-size: 0.8em;
15
+ margin: 0 0.2em;
16
+ padding: 0.3em 0.5em;
17
+ text-transform: uppercase;
18
+
19
+ &:hover {
20
+ background: #ccc;
21
+ }
22
+
23
+ .ObValueToggle-input:checked + & {
24
+ --color-bg: var(--brand-dark);
25
+ background-color: #666;
26
+ background-color: var(--color-bg);
27
+ cursor: default;
28
+ color: white;
29
+ }
30
+
31
+ .ObValueToggle-input:checked:focus-within + & {
32
+ --color-bg: var(--brand-light);
33
+ }
34
+
35
+ .ObValueToggle-input:checked:hover + & {
36
+ background-color: #666;
37
+ background-color: var(--color-bg);
38
+ }
39
39
  }
40
40
 
41
41
  .ObValueToggle-input {
42
- position: absolute;
43
- width: 1px;
44
- height: 1px;
45
- padding: 0;
46
- margin: -1px;
47
- overflow: hidden;
48
- clip: rect(0, 0, 0, 0);
49
- border: 0;
42
+ position: absolute;
43
+ width: 1px;
44
+ height: 1px;
45
+ padding: 0;
46
+ margin: -1px;
47
+ overflow: hidden;
48
+ clip: rect(0, 0, 0, 0);
49
+ border: 0;
50
50
  }