@geoffcox/sterling-svelte 0.0.12 → 0.0.14

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.
@@ -11,11 +11,9 @@ const inputId = uuid();
11
11
  -->
12
12
  <div class="sterling-input">
13
13
  {#if $$slots.label}
14
- <div class="label">
15
- <Label {disabled} for={inputId}>
16
- <slot name="label" />
17
- </Label>
18
- </div>
14
+ <Label {disabled} for={inputId}>
15
+ <slot name="label" />
16
+ </Label>
19
17
  {/if}
20
18
  <input
21
19
  bind:value
@@ -92,7 +90,7 @@ const inputId = uuid();
92
90
  .sterling-input input {
93
91
  font: inherit;
94
92
  color: inherit;
95
- padding: 0.5em 0.5em;
93
+ padding: 0.5em;
96
94
  }
97
95
 
98
96
  .sterling-input input,
@@ -113,9 +111,13 @@ const inputId = uuid();
113
111
  color: var(--Display__color--disabled);
114
112
  }
115
113
 
116
- .label {
114
+ .sterling-input > :global(label) {
117
115
  font-size: 0.7em;
118
- margin: 0.5em 0 0 0.7em;
116
+ margin: 0.5em 0.7em;
117
+ }
118
+
119
+ .sterling-input > :global(label):empty {
120
+ margin: 0;
119
121
  }
120
122
 
121
123
  @media (prefers-reduced-motion) {
@@ -3,7 +3,7 @@ import { v4 as uuid } from "uuid";
3
3
  import { computePosition, flip, offset, shift, autoUpdate } from "@floating-ui/dom";
4
4
  import { clickOutside } from "../clickOutside";
5
5
  import Label from "../display/Label.svelte";
6
- import List from "../lists/List.svelte";
6
+ import List from "../containers/List.svelte";
7
7
  import Input from "./Input.svelte";
8
8
  export let disabled = false;
9
9
  export let items = [];
@@ -130,7 +130,6 @@ const onListClick = (event) => {
130
130
  };
131
131
  const onPendingItemSelected = (event) => {
132
132
  pendingSelectedIndex = event.detail.index;
133
- console.log("pendingSelectedIndex changed");
134
133
  if (!open) {
135
134
  selectedIndex = pendingSelectedIndex;
136
135
  }
@@ -177,11 +176,16 @@ A single item that can be selected from a popup list of items.
177
176
  {...$$restProps}
178
177
  >
179
178
  {#if $$slots.label}
180
- <div class="label">
181
- <Label {disabled} for={inputId}>
182
- <slot name="label" />
183
- </Label>
184
- </div>
179
+ <Label {disabled} for={inputId}>
180
+ <!-- BUGBUG: Problem with slot let params conflict
181
+ It seems that when a default slot is used multiple times in a module,
182
+ the first time sets the possible let params.
183
+ If we don't define the same let params on this label slot that
184
+ is the default slot for label, then using the default slot for list
185
+ will error saying the property is not defined.
186
+ -->
187
+ <slot name="label" index={0} item={undefined} selected={false} />
188
+ </Label>
185
189
  {/if}
186
190
  <div class="input" id={inputId}>
187
191
  <div class="value">
@@ -204,21 +208,19 @@ A single item that can be selected from a popup list of items.
204
208
  >
205
209
  <div class="popup-content">
206
210
  <slot name="list">
207
- {#if $$slots.default === true}
211
+ {#if $$slots.default}
208
212
  <List
209
213
  bind:this={listRef}
210
214
  selectedIndex={pendingSelectedIndex}
211
215
  {items}
212
216
  {disabled}
213
- let:disabled
214
- let:index
215
- let:item
216
- let:selected
217
217
  on:click={onListClick}
218
218
  on:keydown={onListKeydown}
219
219
  on:itemSelected={onPendingItemSelected}
220
220
  >
221
- <slot {disabled} {index} {item} {selected} />
221
+ <svelte:fragment let:disabled let:index let:item let:selected>
222
+ <slot {disabled} {index} {item} {selected} />
223
+ </svelte:fragment>
222
224
  </List>
223
225
  {:else}
224
226
  <List
@@ -226,10 +228,6 @@ A single item that can be selected from a popup list of items.
226
228
  selectedIndex={pendingSelectedIndex}
227
229
  {items}
228
230
  {disabled}
229
- let:disabled
230
- let:index
231
- let:item
232
- let:selected
233
231
  on:click={onListClick}
234
232
  on:keydown={onListKeydown}
235
233
  on:itemSelected={onPendingItemSelected}
@@ -276,9 +274,13 @@ A single item that can be selected from a popup list of items.
276
274
  outline: none;
277
275
  }
278
276
 
279
- .label {
277
+ .sterling-select > :global(label) {
280
278
  font-size: 0.7em;
281
- margin: 0.5em 0.7em 0 0.7em;
279
+ margin: 0.5em 0.7em;
280
+ }
281
+
282
+ .sterling-select > :global(label):empty {
283
+ margin: 0;
282
284
  }
283
285
 
284
286
  .input {
@@ -1,14 +1,14 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
2
+ declare class __sveltets_Render<T> {
3
+ props(): {
4
4
  [x: string]: any;
5
5
  disabled?: boolean | undefined;
6
- items?: any[] | undefined;
6
+ items?: T[] | undefined;
7
7
  open?: boolean | undefined;
8
8
  selectedIndex?: number | undefined;
9
- selectedItem?: any;
9
+ selectedItem?: T | undefined;
10
10
  };
11
- events: {
11
+ events(): {
12
12
  blur: FocusEvent;
13
13
  click: MouseEvent;
14
14
  copy: ClipboardEvent;
@@ -34,8 +34,12 @@ declare const __propDef: {
34
34
  } & {
35
35
  [evt: string]: CustomEvent<any>;
36
36
  };
37
- slots: {
38
- label: {};
37
+ slots(): {
38
+ label: {
39
+ index: number;
40
+ item: undefined;
41
+ selected: boolean;
42
+ };
39
43
  value: {};
40
44
  button: {
41
45
  open: boolean;
@@ -48,11 +52,11 @@ declare const __propDef: {
48
52
  selected: any;
49
53
  };
50
54
  };
51
- };
52
- export type SelectProps = typeof __propDef.props;
53
- export type SelectEvents = typeof __propDef.events;
54
- export type SelectSlots = typeof __propDef.slots;
55
+ }
56
+ export type SelectProps<T> = ReturnType<__sveltets_Render<T>['props']>;
57
+ export type SelectEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
58
+ export type SelectSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
55
59
  /** A single item that can be selected from a popup list of items. */
56
- export default class Select extends SvelteComponentTyped<SelectProps, SelectEvents, SelectSlots> {
60
+ export default class Select<T> extends SvelteComponentTyped<SelectProps<T>, SelectEvents<T>, SelectSlots<T>> {
57
61
  }
58
62
  export {};
@@ -126,11 +126,9 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
126
126
  -->
127
127
  <div class="sterling-slider" class:vertical>
128
128
  {#if $$slots.label}
129
- <div class="label">
130
- <Label {disabled} for={inputId}>
131
- <slot name="label" />
132
- </Label>
133
- </div>
129
+ <Label {disabled} for={inputId}>
130
+ <slot name="label" />
131
+ </Label>
134
132
  {/if}
135
133
  <div
136
134
  class="slider"
@@ -174,7 +172,7 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
174
172
  height: 100%;
175
173
  }
176
174
 
177
- .label {
175
+ .sterling-slider > :global(label) {
178
176
  font-size: 0.7em;
179
177
  }
180
178
 
@@ -0,0 +1,154 @@
1
+ <script>import { v4 as uuid } from "uuid";
2
+ import Label from "../display/Label.svelte";
3
+ export let value;
4
+ export let resize = "none";
5
+ export let disabled = false;
6
+ export let autoHeight = false;
7
+ const inputId = uuid();
8
+ let textAreaRef;
9
+ const autoSetHeight = () => {
10
+ if (autoHeight && textAreaRef) {
11
+ textAreaRef.style.height = "auto";
12
+ textAreaRef.style.height = `${textAreaRef.scrollHeight}px`;
13
+ }
14
+ };
15
+ const onInput = () => {
16
+ autoSetHeight();
17
+ };
18
+ $:
19
+ autoHeight, autoSetHeight();
20
+ </script>
21
+
22
+ <div class="sterling-text-area" style={`--TextArea__resize: ${resize};`}>
23
+ {#if $$slots.label}
24
+ <Label {disabled} for={inputId}>
25
+ <slot name="label" />
26
+ </Label>
27
+ {/if}
28
+ <textarea
29
+ {...$$restProps}
30
+ bind:this={textAreaRef}
31
+ bind:value
32
+ on:blur
33
+ on:click
34
+ on:change
35
+ on:copy
36
+ on:cut
37
+ on:paste
38
+ on:dblclick
39
+ on:focus
40
+ on:focusin
41
+ on:focusout
42
+ on:input={onInput}
43
+ on:input
44
+ on:invalid
45
+ on:keydown
46
+ on:keypress
47
+ on:keyup
48
+ on:mousedown
49
+ on:mouseenter
50
+ on:mouseleave
51
+ on:mousemove
52
+ on:mouseover
53
+ on:mouseout
54
+ on:mouseup
55
+ on:select
56
+ on:submit
57
+ on:reset
58
+ on:wheel
59
+ {disabled}
60
+ rows="1"
61
+ {...$$restProps}
62
+ />
63
+ </div>
64
+
65
+ <style>
66
+ .sterling-text-area {
67
+ background-color: var(--Input__background-color);
68
+ border-color: var(--Input__border-color);
69
+ border-radius: var(--Input__border-radius);
70
+ border-style: var(--Input__border-style);
71
+ border-width: var(--Input__border-width);
72
+ box-sizing: border-box;
73
+ color: var(--Input__color);
74
+ overflow: hidden;
75
+ width: 100%;
76
+ height: 100%;
77
+ display: grid;
78
+ grid-template-columns: 1fr;
79
+ grid-template-rows: 1fr;
80
+ padding: 0;
81
+ margin: 0;
82
+ transition: background-color 250ms, color 250ms, border-color 250ms;
83
+ }
84
+
85
+ .sterling-text-area:hover {
86
+ background-color: var(--Input__background-color--hover);
87
+ border-color: var(--Input__border-color--hover);
88
+ color: var(--Input__color--hover);
89
+ }
90
+
91
+ .sterling-text-area:focus-wthin {
92
+ background-color: var(--Input__background-color--focus);
93
+ border-color: var(--Input__border-color--focus);
94
+ color: var(--Input__color--focus);
95
+ outline-color: var(--Common__outline-color);
96
+ outline-offset: var(--Common__outline-offset);
97
+ outline-style: var(--Common__outline-style);
98
+ outline-width: var(--Common__outline-width);
99
+ }
100
+
101
+ .sterling-text-area:disabled {
102
+ background-color: var(--Input__background-color--disabled);
103
+ border-color: var(---Input__border-color--disabled);
104
+ color: var(--Input__color--disabled);
105
+ cursor: not-allowed;
106
+ }
107
+
108
+ textarea {
109
+ background: none;
110
+ box-sizing: border-box;
111
+ color: inherit;
112
+ font: inherit;
113
+ line-height: inherit;
114
+ padding: 0 0.5em 0.5em 0.5em;
115
+ min-height: 3em;
116
+ margin: 0.5em 0 0 0;
117
+ resize: var(--TextArea__resize, none);
118
+ width: 100%;
119
+ }
120
+
121
+ textarea,
122
+ textarea:hover,
123
+ textarea:focus-within,
124
+ textarea:disabled {
125
+ background-color: transparent;
126
+ border: none;
127
+ outline: none;
128
+ }
129
+
130
+ textarea::placeholder {
131
+ color: var(--Display__color--faint);
132
+ transition: background-color 250ms, color 250ms, border-color 250ms;
133
+ }
134
+
135
+ textarea:disabled::placeholder {
136
+ color: var(--Display__color--disabled);
137
+ }
138
+
139
+ .sterling-text-area > :global(label) {
140
+ font-size: 0.7em;
141
+ margin: 0.5em 0.7em;
142
+ }
143
+
144
+ .sterling-text-area > :global(label):empty {
145
+ margin: 0;
146
+ }
147
+
148
+ @media (prefers-reduced-motion) {
149
+ .sterling-text-area,
150
+ .sterling-text-area textarea::placeholder {
151
+ transition: none;
152
+ }
153
+ }
154
+ </style>
@@ -0,0 +1,50 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { TextAreaResize } from './TextArea.types';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ value: string;
7
+ resize?: TextAreaResize | undefined;
8
+ disabled?: boolean | undefined;
9
+ autoHeight?: boolean | undefined;
10
+ };
11
+ events: {
12
+ blur: FocusEvent;
13
+ click: MouseEvent;
14
+ change: Event;
15
+ copy: ClipboardEvent;
16
+ cut: ClipboardEvent;
17
+ paste: ClipboardEvent;
18
+ dblclick: MouseEvent;
19
+ focus: FocusEvent;
20
+ focusin: FocusEvent;
21
+ focusout: FocusEvent;
22
+ input: Event;
23
+ invalid: Event;
24
+ keydown: KeyboardEvent;
25
+ keypress: KeyboardEvent;
26
+ keyup: KeyboardEvent;
27
+ mousedown: MouseEvent;
28
+ mouseenter: MouseEvent;
29
+ mouseleave: MouseEvent;
30
+ mousemove: MouseEvent;
31
+ mouseover: MouseEvent;
32
+ mouseout: MouseEvent;
33
+ mouseup: MouseEvent;
34
+ select: Event;
35
+ submit: SubmitEvent;
36
+ reset: Event;
37
+ wheel: WheelEvent;
38
+ } & {
39
+ [evt: string]: CustomEvent<any>;
40
+ };
41
+ slots: {
42
+ label: {};
43
+ };
44
+ };
45
+ export type TextAreaProps = typeof __propDef.props;
46
+ export type TextAreaEvents = typeof __propDef.events;
47
+ export type TextAreaSlots = typeof __propDef.slots;
48
+ export default class TextArea extends SvelteComponentTyped<TextAreaProps, TextAreaEvents, TextAreaSlots> {
49
+ }
50
+ export {};
@@ -0,0 +1 @@
1
+ export type TextAreaResize = 'none' | 'both' | 'horizontal' | 'vertical';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoffcox/sterling-svelte",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "author": "Geoff Cox",
5
5
  "description": "A modern, accessible, and lightweight component library for Svelte.",
6
6
  "license": "MIT",
@@ -53,6 +53,14 @@
53
53
  "./buttons/Button.svelte": "./buttons/Button.svelte",
54
54
  "./buttons/Button.types": "./buttons/Button.types.js",
55
55
  "./clickOutside": "./clickOutside.js",
56
+ "./containers/List.svelte": "./containers/List.svelte",
57
+ "./containers/ListItem.svelte": "./containers/ListItem.svelte",
58
+ "./containers/Tree.constants": "./containers/Tree.constants.js",
59
+ "./containers/Tree.svelte": "./containers/Tree.svelte",
60
+ "./containers/Tree.types": "./containers/Tree.types.js",
61
+ "./containers/TreeChevron.svelte": "./containers/TreeChevron.svelte",
62
+ "./containers/TreeItem.svelte": "./containers/TreeItem.svelte",
63
+ "./containers/TreeNode.svelte": "./containers/TreeNode.svelte",
56
64
  "./display/Label.svelte": "./display/Label.svelte",
57
65
  "./display/Progress.svelte": "./display/Progress.svelte",
58
66
  "./display/Progress.types": "./display/Progress.types.js",
@@ -63,7 +71,8 @@
63
71
  "./inputs/Select.svelte": "./inputs/Select.svelte",
64
72
  "./inputs/Slider.svelte": "./inputs/Slider.svelte",
65
73
  "./inputs/Switch.svelte": "./inputs/Switch.svelte",
66
- "./lists/List.svelte": "./lists/List.svelte",
74
+ "./inputs/TextArea.svelte": "./inputs/TextArea.svelte",
75
+ "./inputs/TextArea.types": "./inputs/TextArea.types.js",
67
76
  "./surfaces/CloseX.svelte": "./surfaces/CloseX.svelte",
68
77
  "./surfaces/Dialog.svelte": "./surfaces/Dialog.svelte",
69
78
  "./theme/applyDarkTheme": "./theme/applyDarkTheme.js",
@@ -51,7 +51,6 @@ const onCancel = (event) => {
51
51
  return false;
52
52
  };
53
53
  const onSubmit = (event) => {
54
- console.log(event);
55
54
  const anyEvent = event;
56
55
  if (anyEvent?.submitter.type === "submit") {
57
56
  if (dialogRef.open) {
@@ -63,7 +62,6 @@ const onSubmit = (event) => {
63
62
  return false;
64
63
  }
65
64
  } else {
66
- console.log("cancelling");
67
65
  event.preventDefault();
68
66
  return false;
69
67
  }