wx-svelte-core 1.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 (60) hide show
  1. package/license.txt +21 -0
  2. package/package.json +35 -0
  3. package/src/Locale.svelte +17 -0
  4. package/src/components/Area.svelte +70 -0
  5. package/src/components/Button.svelte +187 -0
  6. package/src/components/Calendar.svelte +42 -0
  7. package/src/components/Checkbox.svelte +132 -0
  8. package/src/components/CheckboxGroup.svelte +52 -0
  9. package/src/components/ColorBoard.svelte +311 -0
  10. package/src/components/ColorPicker.svelte +110 -0
  11. package/src/components/ColorSelect.svelte +204 -0
  12. package/src/components/Combo.svelte +228 -0
  13. package/src/components/Counter.svelte +178 -0
  14. package/src/components/DatePicker.svelte +115 -0
  15. package/src/components/DateRangePicker.svelte +138 -0
  16. package/src/components/Dropdown.svelte +125 -0
  17. package/src/components/Field.svelte +91 -0
  18. package/src/components/Globals.svelte +53 -0
  19. package/src/components/Icon.svelte +31 -0
  20. package/src/components/Modal.svelte +115 -0
  21. package/src/components/ModalArea.svelte +32 -0
  22. package/src/components/MultiCombo.svelte +279 -0
  23. package/src/components/Notice.svelte +145 -0
  24. package/src/components/Notices.svelte +20 -0
  25. package/src/components/Pager.svelte +131 -0
  26. package/src/components/Popup.svelte +53 -0
  27. package/src/components/Portal.svelte +42 -0
  28. package/src/components/RadioButton.svelte +129 -0
  29. package/src/components/RadioButtonGroup.svelte +50 -0
  30. package/src/components/RangeCalendar.svelte +134 -0
  31. package/src/components/RichSelect.svelte +149 -0
  32. package/src/components/Segmented.svelte +115 -0
  33. package/src/components/Select.svelte +124 -0
  34. package/src/components/SideArea.svelte +33 -0
  35. package/src/components/Slider.svelte +242 -0
  36. package/src/components/Switch.svelte +88 -0
  37. package/src/components/Tabs.svelte +163 -0
  38. package/src/components/Text.svelte +185 -0
  39. package/src/components/Timepicker.svelte +217 -0
  40. package/src/components/TwoState.svelte +60 -0
  41. package/src/components/calendar/Button.svelte +40 -0
  42. package/src/components/calendar/Duodecade.svelte +97 -0
  43. package/src/components/calendar/Header.svelte +105 -0
  44. package/src/components/calendar/Month.svelte +189 -0
  45. package/src/components/calendar/Panel.svelte +119 -0
  46. package/src/components/calendar/Year.svelte +89 -0
  47. package/src/components/calendar/helpers.js +56 -0
  48. package/src/components/helpers/SuggestDropdown.svelte +79 -0
  49. package/src/components/helpers/colorTransformator.js +146 -0
  50. package/src/components/helpers/colorValidation.js +21 -0
  51. package/src/components/helpers/listnav.js +85 -0
  52. package/src/components/helpers/sliderMove.js +42 -0
  53. package/src/components/helpers.js +6 -0
  54. package/src/index.js +50 -0
  55. package/src/themes/FontOpenSans.svelte +36 -0
  56. package/src/themes/FonttRoboto.svelte +19 -0
  57. package/src/themes/Material.svelte +321 -0
  58. package/src/themes/Willow.svelte +323 -0
  59. package/src/themes/WillowDark.svelte +320 -0
  60. package/whatsnew.md +97 -0
@@ -0,0 +1,311 @@
1
+ <script>
2
+ import { createEventDispatcher, onMount } from "svelte";
3
+ import Button from "./Button.svelte";
4
+
5
+ //helpers
6
+ import { sliderMove } from "./helpers/sliderMove";
7
+ import colorTransformator from "./helpers/colorTransformator";
8
+ import { parseColor } from "./helpers/colorValidation.js";
9
+
10
+ const dispatch = createEventDispatcher();
11
+
12
+ export let value = "#65D3B3";
13
+ export let button = false;
14
+
15
+ let color;
16
+ $: color = parseColor(value) || "#65D3B3";
17
+
18
+ let block;
19
+ let blockTop;
20
+ let blockLeft;
21
+ let blockColor;
22
+
23
+ let colorLine;
24
+ let lineLeft;
25
+
26
+ function moveBlockSlider(dx, dy) {
27
+ const { width, height } = block.getBoundingClientRect();
28
+
29
+ if (dy < 0) dy = 0;
30
+ else if (dy > height) dy = height;
31
+
32
+ if (dx < 0) dx = 0;
33
+ else if (dx > width) dx = width;
34
+
35
+ blockTop = dy;
36
+ blockLeft = dx;
37
+
38
+ setCurrentColor();
39
+ }
40
+
41
+ function setCurrentColor(lineSliderMove) {
42
+ let _sValue, _vValue;
43
+
44
+ if (lineSliderMove) {
45
+ [, _sValue, _vValue] = colorTransformator.hexToHvs(color);
46
+ } else {
47
+ const { width, height } = block.getBoundingClientRect();
48
+
49
+ const pxX = width / 100;
50
+ const pxY = height / 100;
51
+
52
+ _sValue = Math.ceil(blockLeft / pxX) / 100;
53
+ _vValue = Math.ceil(Math.abs(blockTop / pxY - 100)) / 100;
54
+ }
55
+
56
+ value = colorTransformator.hvsToHex(hueColor, _sValue, _vValue);
57
+ }
58
+
59
+ let hueColor;
60
+ $: blockColor = colorTransformator.hvsToHex(hueColor, 1, 1);
61
+
62
+ function moveLineSlider(dx) {
63
+ const width = colorLine.getBoundingClientRect().width;
64
+
65
+ if (dx < 0) dx = 0;
66
+ else if (dx > width) dx = width;
67
+
68
+ toggleLineColor(dx, width);
69
+ }
70
+
71
+ function toggleLineColor(dx, width) {
72
+ width = width || colorLine.getBoundingClientRect().width;
73
+
74
+ lineLeft = dx;
75
+
76
+ const h = Math.round((lineLeft * 359) / width);
77
+ hueColor = Math.max(Math.min(h, 359), 0);
78
+
79
+ setCurrentColor(true);
80
+ }
81
+
82
+ onMount(() => setSlidersPosition());
83
+
84
+ function setSlidersPosition() {
85
+ const [h, s, v] = colorTransformator.hexToHvs(color);
86
+ const { width, height } = block.getBoundingClientRect();
87
+ hueColor = h;
88
+
89
+ lineLeft = (h * colorLine.getBoundingClientRect().width) / 359;
90
+ blockLeft = s * width;
91
+ blockTop = Math.abs(height * (v - 1));
92
+ }
93
+
94
+ function handleChange({ target }) {
95
+ const newColor = parseColor(target.value);
96
+
97
+ value = color = newColor;
98
+ if (newColor) {
99
+ setSlidersPosition();
100
+ }
101
+ }
102
+
103
+ function handleSelect(ev) {
104
+ ev.stopPropagation();
105
+ dispatch("change", { value: color });
106
+ }
107
+
108
+ const BLOCK = "Block";
109
+ const LINE = "Line";
110
+
111
+ function keydown(ev) {
112
+ const slider = ev.target;
113
+ const isSliderBlock = slider === BLOCK;
114
+ const isSliderLine = slider === LINE;
115
+
116
+ let css = window.getComputedStyle(slider);
117
+ let left = parseFloat(css.left);
118
+ let top = parseFloat(css.top);
119
+ const code = ev.code;
120
+
121
+ if (isSliderBlock) {
122
+ switch (code) {
123
+ case "ArrowLeft": {
124
+ left--;
125
+ break;
126
+ }
127
+ case "ArrowRight": {
128
+ left++;
129
+ break;
130
+ }
131
+ case "ArrowDown": {
132
+ top++;
133
+ break;
134
+ }
135
+ case "ArrowUp": {
136
+ top--;
137
+ break;
138
+ }
139
+ default:
140
+ return;
141
+ }
142
+
143
+ moveBlockSlider(left, top);
144
+ }
145
+
146
+ if (isSliderLine) {
147
+ if (code === "ArrowLeft" || code === "ArrowDown") left--;
148
+ else if (code === "ArrowRight" || code === "ArrowUp") left++;
149
+ else return;
150
+ moveLineSlider(left);
151
+ }
152
+
153
+ ev.preventDefault();
154
+ }
155
+ </script>
156
+
157
+ <div class="wx-colorboard">
158
+ <div
159
+ class="wx-color-block"
160
+ style="background: {blockColor};"
161
+ bind:this={block}
162
+ use:sliderMove={{ moveBlockSlider }}
163
+ >
164
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
165
+ <div
166
+ class="wx-color-block-slider wx-slider"
167
+ style="background: {color}; top: {blockTop}px; left:{blockLeft}px;"
168
+ tabindex="0"
169
+ data-slider={BLOCK}
170
+ on:keydown={keydown}
171
+ />
172
+ </div>
173
+ <div
174
+ class="wx-color-line"
175
+ bind:this={colorLine}
176
+ use:sliderMove={{ moveLineSlider }}
177
+ >
178
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
179
+ <div
180
+ class="wx-color-line-slider wx-slider"
181
+ style="background: {blockColor}; left: {lineLeft}px;"
182
+ tabindex="0"
183
+ data-slider={LINE}
184
+ on:keydown={keydown}
185
+ />
186
+ </div>
187
+ <div class="wx-color-controls">
188
+ <div class="wx-color" style="background: {color}" />
189
+ <input
190
+ type="text"
191
+ class="wx-text"
192
+ bind:value
193
+ on:change={handleChange}
194
+ />
195
+ </div>
196
+ {#if button}
197
+ <Button click={handleSelect} type="secondary">Select</Button>
198
+ {/if}
199
+ </div>
200
+
201
+ <style>
202
+ .wx-colorboard {
203
+ display: flex;
204
+ flex-direction: column;
205
+ gap: 12px;
206
+ padding: 8px;
207
+ width: 100%;
208
+ }
209
+
210
+ .wx-color-block {
211
+ height: 140px;
212
+ width: 100%;
213
+ position: relative;
214
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
215
+ }
216
+
217
+ .wx-color-block::before,
218
+ .wx-color-block::after {
219
+ content: "";
220
+ width: 100%;
221
+ height: 100%;
222
+ position: absolute;
223
+ }
224
+ .wx-color-block:before {
225
+ background-image: linear-gradient(0deg, #000, hsla(0, 0%, 100%, 0));
226
+ z-index: 2;
227
+ }
228
+ .wx-color-block::after {
229
+ background-image: linear-gradient(90deg, #fff, hsla(20, 42%, 65%, 0));
230
+ z-index: 1;
231
+ }
232
+
233
+ .wx-color-block-slider {
234
+ height: 16px;
235
+ width: 16px;
236
+ margin: -8px 0 0 -8px;
237
+ }
238
+
239
+ .wx-slider {
240
+ border: 2px solid white;
241
+ border-radius: 50%;
242
+ position: absolute;
243
+ z-index: 3;
244
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
245
+ }
246
+
247
+ .wx-slider:focus,
248
+ .wx-slider:hover {
249
+ outline: none;
250
+ box-shadow:
251
+ 0 1px 3px rgba(0, 0, 0, 0.2),
252
+ inset 0 0 4px #ffffff;
253
+ }
254
+
255
+ .wx-color-line {
256
+ width: 100%;
257
+ height: 8px;
258
+ background-image: linear-gradient(
259
+ 90deg,
260
+ red,
261
+ #ff0 17%,
262
+ #0f0 33%,
263
+ #0ff 50%,
264
+ #00f 67%,
265
+ #f0f 83%,
266
+ red
267
+ );
268
+ position: relative;
269
+ border-radius: 6px;
270
+ }
271
+
272
+ .wx-color-line-slider {
273
+ height: 14px;
274
+ width: 14px;
275
+ margin: 0 0 0 -7px;
276
+ top: -4px;
277
+ }
278
+
279
+ .wx-color-controls {
280
+ display: flex;
281
+ flex-wrap: wrap;
282
+ justify-content: space-between;
283
+ }
284
+
285
+ .wx-color,
286
+ .wx-text {
287
+ width: calc(50% - 4px);
288
+ }
289
+
290
+ .wx-color {
291
+ height: 32px;
292
+ }
293
+
294
+ .wx-text {
295
+ outline: none;
296
+ background: var(--wx-input-background);
297
+ border: var(--wx-input-border);
298
+ border-radius: var(--wx-input-border-radius);
299
+ font-family: var(--wx-input-font-family);
300
+ font-size: var(--wx-input-font-size);
301
+ line-height: var(--wx-input-line-height);
302
+ font-weight: var(--wx-input-font-weight);
303
+ text-align: var(--wx-input-text-align);
304
+ color: var(--wx-input-font-color);
305
+ padding: var(--wx-input-padding);
306
+ }
307
+
308
+ .wx-text:focus {
309
+ border: var(--wx-input-border-focus);
310
+ }
311
+ </style>
@@ -0,0 +1,110 @@
1
+ <script>
2
+ import { uid } from "wx-lib-dom";
3
+ import Dropdown from "./Dropdown.svelte";
4
+ import ColorBoard from "./ColorBoard.svelte";
5
+
6
+ export let value = "";
7
+ export let id = uid();
8
+ export let placeholder = "";
9
+ export let title = "";
10
+ export let disabled = false;
11
+ export let error = false;
12
+
13
+ let popup;
14
+
15
+ function handlePopup() {
16
+ if (disabled) return false;
17
+ popup = true;
18
+ }
19
+
20
+ function selectColor(ev) {
21
+ value = ev.detail.value;
22
+ popup = null;
23
+ }
24
+ </script>
25
+
26
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
27
+ <div class="wx-colorpicker" on:click={handlePopup}>
28
+ <input
29
+ {title}
30
+ {value}
31
+ readonly
32
+ {id}
33
+ {placeholder}
34
+ {disabled}
35
+ class:wx-error={error}
36
+ class:wx-focus={popup}
37
+ />
38
+ <div class="wx-color" style="background: {value}" />
39
+
40
+ {#if popup}
41
+ <Dropdown cancel={() => (popup = null)}>
42
+ <ColorBoard {value} button="true" on:change={selectColor} />
43
+ </Dropdown>
44
+ {/if}
45
+ </div>
46
+
47
+ <style>
48
+ .wx-colorpicker {
49
+ position: relative;
50
+ width: var(--wx-input-width);
51
+ }
52
+
53
+ .wx-color {
54
+ width: var(--wx-input-icon-size);
55
+ height: var(--wx-input-icon-size);
56
+ border-radius: var(--wx-input-border-radius);
57
+ cursor: pointer;
58
+ position: absolute;
59
+ left: var(--wx-input-icon-indent);
60
+ top: 50%;
61
+ transform: translateY(-50%);
62
+ }
63
+
64
+ input {
65
+ display: block;
66
+ width: 100%;
67
+ height: var(--wx-input-height);
68
+ outline: none;
69
+ background: var(--wx-input-background);
70
+ border: var(--wx-input-border);
71
+ border-radius: var(--wx-input-border-radius);
72
+ font-family: var(--wx-input-font-family);
73
+ font-size: var(--wx-input-font-size);
74
+ line-height: var(--wx-input-line-height);
75
+ font-weight: var(--wx-input-font-weight);
76
+ text-align: var(--wx-input-text-align);
77
+ color: var(--wx-input-font-color);
78
+ padding: var(--wx-input-padding);
79
+ padding-right: calc(
80
+ var(--wx-input-icon-size) + var(--wx-input-icon-indent) * 2
81
+ );
82
+ padding-left: calc(
83
+ var(--wx-input-icon-size) + var(--wx-input-icon-indent) * 2
84
+ );
85
+ overflow: hidden;
86
+ text-overflow: ellipsis;
87
+ }
88
+ input.wx-focus {
89
+ border: var(--wx-input-border-focus);
90
+ }
91
+ input::placeholder {
92
+ color: var(--wx-input-placeholder-color);
93
+ }
94
+ input[disabled] {
95
+ cursor: not-allowed;
96
+ border: var(--wx-input-border-disabled);
97
+ color: var(--wx-color-font-disabled);
98
+ background: var(--wx-input-background-disabled);
99
+ }
100
+ input[disabled]::placeholder {
101
+ color: var(--wx-color-font-disabled);
102
+ }
103
+ input[disabled] ~ .wx-color {
104
+ cursor: not-allowed;
105
+ }
106
+ input.wx-error {
107
+ border-color: var(--wx-color-danger);
108
+ color: var(--wx-color-danger);
109
+ }
110
+ </style>
@@ -0,0 +1,204 @@
1
+ <script>
2
+ import { uid } from "wx-lib-dom";
3
+ import Dropdown from "./Dropdown.svelte";
4
+
5
+ export let colors = [
6
+ "#00a037",
7
+ "#df282f",
8
+ "#fd772c",
9
+ "#6d4bce",
10
+ "#b26bd3",
11
+ "#c87095",
12
+ "#90564d",
13
+ "#eb2f89",
14
+ "#ea77c0",
15
+ "#777676",
16
+ "#a9a8a8",
17
+ "#9bb402",
18
+ "#e7a90b",
19
+ "#0bbed7",
20
+ "#038cd9",
21
+ ];
22
+ export let value = "";
23
+ export let id = uid();
24
+ export let clear = true;
25
+ export let placeholder = "";
26
+ export let title;
27
+ export let disabled = false;
28
+ export let error = false;
29
+
30
+ let popup;
31
+
32
+ function selectColor(color) {
33
+ value = color;
34
+ popup = null;
35
+ }
36
+ function handleClear() {
37
+ value = null;
38
+ }
39
+ function handlePopup() {
40
+ if (disabled) return false;
41
+ popup = true;
42
+ }
43
+ </script>
44
+
45
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
46
+ <div class="wx-colorselect" on:click={handlePopup}>
47
+ <input
48
+ {title}
49
+ {value}
50
+ readonly
51
+ {id}
52
+ {placeholder}
53
+ {disabled}
54
+ class:wx-error={error}
55
+ class:wx-focus={popup}
56
+ />
57
+
58
+ {#if clear && value && !disabled}
59
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
60
+ <i class="wx-clear wxi-close" on:click|stopPropagation={handleClear} />
61
+ {/if}
62
+
63
+ {#if value}
64
+ <div
65
+ class="wx-color wx-selected"
66
+ style="background-color: {value || '#00a037'}"
67
+ />
68
+ {:else}
69
+ <div class="wx-empty wx-selected" />
70
+ {/if}
71
+
72
+ {#if popup}
73
+ <Dropdown cancel={() => (popup = null)}>
74
+ <div class="wx-colors">
75
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
76
+ <div
77
+ class="wx-empty"
78
+ on:click|stopPropagation={() => selectColor("")}
79
+ />
80
+ {#each colors as color}
81
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
82
+ <div
83
+ class="wx-color"
84
+ style="background-color: {color}"
85
+ on:click|stopPropagation={() => selectColor(color)}
86
+ />
87
+ {/each}
88
+ </div>
89
+ </Dropdown>
90
+ {/if}
91
+ </div>
92
+
93
+ <style>
94
+ .wx-colorselect {
95
+ position: relative;
96
+ width: var(--wx-input-width);
97
+ }
98
+
99
+ .wx-selected {
100
+ position: absolute;
101
+ left: var(--wx-input-icon-indent);
102
+ top: 50%;
103
+ transform: translateY(-50%);
104
+ }
105
+
106
+ .wx-colors {
107
+ display: flex;
108
+ flex-wrap: wrap;
109
+ gap: 8px;
110
+ padding: 8px;
111
+ }
112
+
113
+ .wx-color {
114
+ width: var(--wx-input-icon-size);
115
+ height: var(--wx-input-icon-size);
116
+ border-radius: var(--wx-input-border-radius);
117
+ cursor: pointer;
118
+ }
119
+
120
+ input {
121
+ display: block;
122
+ width: 100%;
123
+ height: var(--wx-input-height);
124
+ outline: none;
125
+ background: var(--wx-input-background);
126
+ border: var(--wx-input-border);
127
+ border-radius: var(--wx-input-border-radius);
128
+ font-family: var(--wx-input-font-family);
129
+ font-size: var(--wx-input-font-size);
130
+ line-height: var(--wx-input-line-height);
131
+ font-weight: var(--wx-input-font-weight);
132
+ text-align: var(--wx-input-text-align);
133
+ color: var(--wx-input-font-color);
134
+ padding: var(--wx-input-padding);
135
+ padding-right: calc(
136
+ var(--wx-input-icon-size) + var(--wx-input-icon-indent) * 2
137
+ );
138
+ padding-left: calc(
139
+ var(--wx-input-icon-size) + var(--wx-input-icon-indent) * 2
140
+ );
141
+ overflow: hidden;
142
+ text-overflow: ellipsis;
143
+ }
144
+ input.wx-focus {
145
+ border: var(--wx-input-border-focus);
146
+ }
147
+ input::placeholder {
148
+ color: var(--wx-input-placeholder-color);
149
+ }
150
+ input[disabled] {
151
+ cursor: not-allowed;
152
+ border: var(--wx-input-border-disabled);
153
+ color: var(--wx-color-font-disabled);
154
+ background: var(--wx-input-background-disabled);
155
+ }
156
+ input[disabled]::placeholder {
157
+ color: var(--wx-color-font-disabled);
158
+ }
159
+ input[disabled] ~ .wx-color,
160
+ input[disabled] ~ .wx-empty {
161
+ cursor: not-allowed;
162
+ }
163
+ input.wx-error {
164
+ border-color: var(--wx-color-danger);
165
+ color: var(--wx-color-danger);
166
+ }
167
+
168
+ .wx-empty {
169
+ width: var(--wx-input-icon-size);
170
+ height: var(--wx-input-icon-size);
171
+ border: var(--wx-input-border);
172
+ border-radius: var(--wx-input-border-radius);
173
+ background: linear-gradient(
174
+ to top left,
175
+ rgba(0, 0, 0, 0) 0%,
176
+ rgba(0, 0, 0, 0) calc(50% - 1px),
177
+ rgb(255, 0, 0) 50%,
178
+ rgba(0, 0, 0, 0) calc(50% + 1px),
179
+ rgba(0, 0, 0, 0) 100%
180
+ );
181
+ cursor: pointer;
182
+ user-select: none;
183
+ }
184
+
185
+ .wx-clear {
186
+ position: absolute;
187
+ right: var(--wx-input-icon-indent);
188
+ top: 50%;
189
+ transform: translateY(-50%);
190
+ font-size: var(--wx-input-icon-size);
191
+ line-height: 1;
192
+ display: flex;
193
+ justify-content: center;
194
+ align-items: center;
195
+ width: var(--wx-input-icon-size);
196
+ height: var(--wx-input-icon-size);
197
+ border-radius: var(--wx-input-border-radius);
198
+ color: var(--wx-input-icon-color);
199
+ cursor: pointer;
200
+ }
201
+ .wx-clear:hover {
202
+ background: var(--wx-background-hover);
203
+ }
204
+ </style>