@dosgato/dialog 1.2.4 → 1.2.5

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,8 +1,9 @@
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, randomid, shouldUseWhiteText } from 'txstate-utils';
3
+ import { get, isNotBlank, isNotNull, keyby, randomid } from 'txstate-utils';
4
4
  import { Radio } from '..';
5
5
  import FieldStandard from '../FieldStandard.svelte';
6
+ import { ScreenReaderOnly } from '@txstate-mws/svelte-components';
6
7
  export let id = undefined;
7
8
  let className = '';
8
9
  export { className as class };
@@ -19,6 +20,7 @@ const groupid = randomid();
19
20
  const store = getContext(FORM_CONTEXT);
20
21
  const inheritedPath = getContext(FORM_INHERITED_PATH);
21
22
  const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
23
+ $: colorsByValue = keyby(options, 'value');
22
24
  async function reactToOptions(..._) {
23
25
  const val = get($store.data, finalPath);
24
26
  if (!val)
@@ -38,22 +40,31 @@ onMount(reactToOptions);
38
40
  {#if addAllOption}
39
41
  <label for={`${groupid}.alt`} class="colorsel alternating">
40
42
  <Radio id={`${groupid}.alt`} name={groupid} value="alternating" selected={value === 'alternating'} {onChange} {onBlur} {helptextid}/>
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>
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>
47
51
  </label>
48
52
  {/if}
49
53
  {#each options as option, idx (option.value) }
50
54
  {@const radioid = `${groupid}.${idx}`}
51
- <label for={radioid} class="colorsel">
55
+ <label for={radioid} class="colorsel" title={option.name || option.value}>
52
56
  <Radio id={radioid} name={groupid} value={option.value} selected={value === option.value} {onChange} {onBlur} {helptextid}/>
53
- <span class="picker-text" style:background-color={option.color} class:dark={shouldUseWhiteText(option.color)}>{option.name || option.value}</span>
57
+ <div class="picker-text" style:background-color={option.color}>
58
+ <ScreenReaderOnly>{option.name || option.value}</ScreenReaderOnly>
59
+ </div>
54
60
  </label>
55
61
  {/each}
56
62
  </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}
57
68
  </div>
58
69
  </FieldStandard>
59
70
 
@@ -63,21 +74,11 @@ onMount(reactToOptions);
63
74
  container-name: color-picker-container;
64
75
  }
65
76
  .color-container {
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
- }
77
+ display: flex;
78
+ flex-wrap: wrap;
79
+ gap: 1em;
80
+ margin-bottom: 1em;
79
81
  }
80
-
81
82
  label.colorsel :global(input[type="radio"]) {
82
83
  border: 0;
83
84
  clip: rect(0 0 0 0);
@@ -88,54 +89,33 @@ onMount(reactToOptions);
88
89
  position: absolute;
89
90
  width: 1px;
90
91
  }
91
-
92
- label.colorsel :global(input[type="radio"] + span) {
93
- display: inline-block;
94
- padding: 1rem;
95
- width: 100%;
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%;
96
100
  text-align: center;
97
101
  white-space: nowrap;
98
102
  border: 1px solid #D1D1D1;
99
103
  }
100
104
 
101
- label.colorsel :global(input[type="radio"]:checked + span) {
105
+ label.colorsel :global(input[type="radio"]:checked + div.picker-text) {
102
106
  outline: 5px solid #93BBC4;
103
107
  }
104
108
 
105
- label.colorsel :global(input[type="radio"]:focus + span) {
109
+ label.colorsel :global(input[type="radio"]:focus + div.picker-text) {
106
110
  outline: 5px solid blue;
107
111
  }
108
-
109
- label.colorsel.alternating {
110
- position: relative;
112
+ label.colorsel.alternating .picker-text {
113
+ overflow: hidden;
111
114
  }
112
-
113
- label.colorsel.alternating span.alternating-bg {
115
+ label.colorsel.alternating .picker-text .alternating-bg {
114
116
  display: flex;
115
- padding: 0;
116
117
  height: 100%;
117
- }
118
-
119
- label.colorsel.alternating span.alternating-bg span {
120
118
  width: 100%;
121
119
  }
122
120
 
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
-
141
121
  </style>