@dosgato/dialog 1.2.5 → 1.2.7

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.
@@ -1,6 +1,7 @@
1
1
  <script>import { datetimeSerialize, datetimeDeserialize } from '@txstate-mws/svelte-forms';
2
2
  import FieldStandard from './FieldStandard.svelte';
3
3
  import Input from './Input.svelte';
4
+ import { createEventDispatcher } from 'svelte';
4
5
  let className = '';
5
6
  export { className as class };
6
7
  export let id = undefined;
@@ -16,23 +17,26 @@ export let related = 0;
16
17
  export let extradescid = undefined;
17
18
  export let helptext = undefined;
18
19
  export let inputelement = undefined;
19
- let showBadInputMessage = false;
20
- function wrapOnBlur(onBlur) {
21
- const date = new Date(inputelement.value);
22
- showBadInputMessage = inputelement.validity.badInput || !(date instanceof Date && !isNaN(date.valueOf()));
23
- onBlur();
20
+ const dispatch = createEventDispatcher();
21
+ function onChange(setVal) {
22
+ return () => {
23
+ if (inputelement) {
24
+ const date = new Date(inputelement.value);
25
+ const invalid = inputelement.validity.badInput || !(date instanceof Date && !isNaN(date.valueOf()));
26
+ if (invalid) {
27
+ setVal(undefined);
28
+ dispatch('change', undefined);
29
+ }
30
+ else {
31
+ setVal(datetimeDeserialize(inputelement.value));
32
+ dispatch('change', datetimeDeserialize(inputelement.value));
33
+ }
34
+ }
35
+ };
24
36
  }
25
37
  </script>
26
38
 
27
- <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} serialize={datetimeSerialize} deserialize={datetimeDeserialize} let:value let:valid let:invalid let:id let:onBlur let:onChange let:helptextid let:messagesid>
28
- {#if showBadInputMessage}<div class="bad-input-warning" aria-live='polite'>{`Field ${label}`} must include both a date and time</div>{/if}
29
- <Input bind:inputelement={inputelement} type="datetime-local" name={path} {value} {id} class="dialog-input {className}" onBlur={() => { wrapOnBlur(onBlur) }} {onChange} {valid} {invalid} {min} {max} {step} {extradescid} {messagesid} {helptextid}/>
39
+ <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} serialize={datetimeSerialize} deserialize={datetimeDeserialize} let:value let:valid let:invalid let:id let:onBlur let:helptextid let:messagesid let:setVal>
40
+ <Input bind:inputelement={inputelement} type="datetime-local" name={path} {value} {id} class="dialog-input {className}" {onBlur} onChange={onChange(setVal)} {valid} {invalid} {min} {max} {step} {extradescid} {messagesid} {helptextid}/>
30
41
  </FieldStandard>
31
42
 
32
- <style>
33
- .bad-input-warning {
34
- margin-bottom: 0.3em;
35
- color: var(--dg-danger-bg, #9a3332);
36
- }
37
-
38
- </style>
@@ -21,6 +21,8 @@ declare const __propDef: {
21
21
  inputelement?: HTMLInputElement;
22
22
  };
23
23
  events: {
24
+ change: CustomEvent<any>;
25
+ } & {
24
26
  [evt: string]: CustomEvent<any>;
25
27
  };
26
28
  slots: {};
@@ -31,7 +31,7 @@ declare const __propDef: {
31
31
  default: {
32
32
  path: string;
33
33
  index: number;
34
- value: unknown;
34
+ value: any;
35
35
  maxed: boolean;
36
36
  maxLength: number;
37
37
  currentLength: number;
@@ -31,7 +31,7 @@ declare const __propDef: {
31
31
  value: any;
32
32
  onBlur: () => void;
33
33
  onChange: (e?: any) => void;
34
- setVal: (val: string | number | boolean | object | Date | undefined, notDirty?: boolean | undefined) => void;
34
+ setVal: (val: string | number | boolean | object | Date | undefined, notDirty?: boolean) => void;
35
35
  valid: boolean;
36
36
  invalid: boolean;
37
37
  messagesid: string | undefined;
@@ -90,7 +90,7 @@ function iconForItem(item) {
90
90
  {#if $store.initialized}
91
91
  <Tree headers={[
92
92
  { label: 'Path', id: 'name', grow: 4, icon: item => iconForItem(item), get: 'name' }
93
- ]} singleSelect store={treeStore} on:deselect={onDeselect} on:choose={onChoose} />
93
+ ]} singleSelect store={treeStore} on:deselect={onDeselect} on:choose={onChoose} searchable='name' />
94
94
  {/if}
95
95
  </section>
96
96
  <ChooserPreview {thumbnailExpanded} {previewId} {store} on:thumbnailsizechange={() => { thumbnailExpanded = !thumbnailExpanded }}/>
@@ -1,9 +1,8 @@
1
1
  <script>import { FORM_CONTEXT, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
2
2
  import { getContext, onMount } from 'svelte';
3
- import { get, isNotBlank, isNotNull, keyby, randomid } from 'txstate-utils';
3
+ import { get, isNotBlank, randomid, shouldUseWhiteText } from 'txstate-utils';
4
4
  import { Radio } from '..';
5
5
  import FieldStandard from '../FieldStandard.svelte';
6
- import { ScreenReaderOnly } from '@txstate-mws/svelte-components';
7
6
  export let id = undefined;
8
7
  let className = '';
9
8
  export { className as class };
@@ -20,7 +19,6 @@ const groupid = randomid();
20
19
  const store = getContext(FORM_CONTEXT);
21
20
  const inheritedPath = getContext(FORM_INHERITED_PATH);
22
21
  const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
23
- $: colorsByValue = keyby(options, 'value');
24
22
  async function reactToOptions(..._) {
25
23
  const val = get($store.data, finalPath);
26
24
  if (!val)
@@ -40,31 +38,22 @@ onMount(reactToOptions);
40
38
  {#if addAllOption}
41
39
  <label for={`${groupid}.alt`} class="colorsel alternating">
42
40
  <Radio id={`${groupid}.alt`} name={groupid} value="alternating" selected={value === 'alternating'} {onChange} {onBlur} {helptextid}/>
43
- <div class="picker-text">
44
- <ScreenReaderOnly>Alternating</ScreenReaderOnly>
45
- <div class="alternating-bg">
46
- {#each options as option (option.value)}
47
- <div style:background-color={option.color} style:flex-basis={`calc(100% / ${options.length})`}></div>
48
- {/each}
49
- </div>
50
- </div>
41
+ <span class="alternating-bg">
42
+ {#each options as option (option.value)}
43
+ <span style:background-color={option.color}></span>
44
+ {/each}
45
+ </span>
46
+ <span class="picker-text">Alternating</span>
51
47
  </label>
52
48
  {/if}
53
49
  {#each options as option, idx (option.value) }
54
50
  {@const radioid = `${groupid}.${idx}`}
55
- <label for={radioid} class="colorsel" title={option.name || option.value}>
51
+ <label for={radioid} class="colorsel">
56
52
  <Radio id={radioid} name={groupid} value={option.value} selected={value === option.value} {onChange} {onBlur} {helptextid}/>
57
- <div class="picker-text" style:background-color={option.color}>
58
- <ScreenReaderOnly>{option.name || option.value}</ScreenReaderOnly>
59
- </div>
53
+ <span class="picker-text" style:background-color={option.color} class:dark={shouldUseWhiteText(option.color)}>{option.name || option.value}</span>
60
54
  </label>
61
55
  {/each}
62
56
  </div>
63
- {#if options.length && isNotNull(get($store.data, finalPath))}
64
- <div>
65
- Selected Color: <span class="selected-color">{get($store.data, finalPath) === 'alternating' ? 'Alternating' : (colorsByValue[get($store.data, finalPath)]?.name ?? get($store.data, finalPath))}</span>
66
- </div>
67
- {/if}
68
57
  </div>
69
58
  </FieldStandard>
70
59
 
@@ -74,11 +63,21 @@ onMount(reactToOptions);
74
63
  container-name: color-picker-container;
75
64
  }
76
65
  .color-container {
77
- display: flex;
78
- flex-wrap: wrap;
79
- gap: 1em;
80
- margin-bottom: 1em;
66
+ display: grid;
67
+ grid-gap: 10px;
68
+ grid-template-columns: 1fr 1fr 1fr 1fr;
69
+ }
70
+ @container color-picker-container (max-width: 600px) {
71
+ .color-container {
72
+ grid-template-columns: 1fr 1fr 1fr;
73
+ }
74
+ }
75
+ @container color-picker-container (max-width: 350px) {
76
+ .color-container {
77
+ grid-template-columns: 1fr 1fr;
78
+ }
81
79
  }
80
+
82
81
  label.colorsel :global(input[type="radio"]) {
83
82
  border: 0;
84
83
  clip: rect(0 0 0 0);
@@ -89,33 +88,54 @@ onMount(reactToOptions);
89
88
  position: absolute;
90
89
  width: 1px;
91
90
  }
92
- label.colorsel :global(input[type="radio"] + div.picker-text) {
93
- position: relative;
94
- display: flex;
95
- justify-content: center;
96
- align-items: center;
97
- width: 50px;
98
- height: 50px;
99
- border-radius: 100%;
91
+
92
+ label.colorsel :global(input[type="radio"] + span) {
93
+ display: inline-block;
94
+ padding: 1rem;
95
+ width: 100%;
100
96
  text-align: center;
101
97
  white-space: nowrap;
102
98
  border: 1px solid #D1D1D1;
103
99
  }
104
100
 
105
- label.colorsel :global(input[type="radio"]:checked + div.picker-text) {
101
+ label.colorsel :global(input[type="radio"]:checked + span) {
106
102
  outline: 5px solid #93BBC4;
107
103
  }
108
104
 
109
- label.colorsel :global(input[type="radio"]:focus + div.picker-text) {
105
+ label.colorsel :global(input[type="radio"]:focus + span) {
110
106
  outline: 5px solid blue;
111
107
  }
112
- label.colorsel.alternating .picker-text {
113
- overflow: hidden;
108
+
109
+ label.colorsel.alternating {
110
+ position: relative;
114
111
  }
115
- label.colorsel.alternating .picker-text .alternating-bg {
112
+
113
+ label.colorsel.alternating span.alternating-bg {
116
114
  display: flex;
115
+ padding: 0;
117
116
  height: 100%;
117
+ }
118
+
119
+ label.colorsel.alternating span.alternating-bg span {
118
120
  width: 100%;
119
121
  }
120
122
 
123
+ label.colorsel.alternating span.picker-text {
124
+ position: absolute;
125
+ left: 50%;
126
+ top: 50%;
127
+ transform: translate(-50%, -50%);
128
+ }
129
+
130
+ label .picker-text {
131
+ font-weight: bold;
132
+ letter-spacing: 0.5px;
133
+ color: black;
134
+ text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.6), 1px -1px 1px rgba(255, 255, 255, 0.6), -1px 1px 1px rgba(255, 255, 255, 0.6), -1px -1px 1px rgba(255, 255, 255, 0.6);
135
+ }
136
+ label .picker-text.dark, label.alternating .picker-text {
137
+ color: white;
138
+ text-shadow: 1px 1px 1px #222, 1px -1px 1px #222, -1px 1px 1px #222, -1px -1px 1px #222;
139
+ }
140
+
121
141
  </style>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dosgato/dialog",
3
3
  "description": "A component library for building forms that edit a JSON document.",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
7
7
  "dev": "vite dev --force",
@@ -35,6 +35,7 @@
35
35
  "@sveltejs/adapter-auto": "^3.0.0",
36
36
  "@sveltejs/kit": "^2.0.1",
37
37
  "@sveltejs/package": "^2.0.1",
38
+ "@sveltejs/vite-plugin-svelte": "^3.0.0",
38
39
  "eslint-config-standard-with-typescript": "^43.0.0",
39
40
  "eslint-plugin-svelte": "^2.0.0",
40
41
  "svelte-check": "^3.0.1",