@substrate-system/select 0.0.0-stage → 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,168 @@
1
+ # Big Time Public License
2
+
3
+ Version 2.0.2
4
+
5
+ <https://bigtimelicense.com/versions/2.0.2>
6
+
7
+ ## Purpose
8
+
9
+ These terms let you use and share this software for noncommercial purposes
10
+ and in small business for free, while also guaranteeing that paid licenses
11
+ for big businesses will be available on fair, reasonable, and
12
+ nondiscriminatory terms.
13
+
14
+ ## Acceptance
15
+
16
+ In order to get any license under these terms, you must agree to them as
17
+ both strict obligations and conditions to all your licenses.
18
+
19
+ ## Noncommercial Purposes
20
+
21
+ You may use the software for any noncommercial purpose.
22
+
23
+ ## Personal Uses
24
+
25
+ Personal use for research, experiment, and testing for the benefit of
26
+ public knowledge, personal study, private entertainment, hobby projects,
27
+ amateur pursuits, or religious observance, without any anticipated
28
+ commercial application, count as use for noncommercial purposes.
29
+
30
+ ## Noncommercial Organizations
31
+
32
+ Use by any charitable organization, educational institution, public
33
+ research organization, public safety or health organization, environmental
34
+ protection organization, or government institution counts as use for
35
+ noncommercial purposes, regardless of the source of funding or obligations
36
+ resulting from the funding.
37
+
38
+ ## Small Business
39
+
40
+ You may use the software for the benefit of your company if it meets all
41
+ these criteria:
42
+
43
+ 1. had fewer than 20 total individuals working as employees and
44
+ independent contractors at all times during the last tax year
45
+
46
+ 2. earned less than $1,000,000 total revenue in the last tax year
47
+
48
+ 3. received less than $1,000,000 total debt, equity, and other investment
49
+ in the last five tax years, counting investment in predecessor
50
+ companies that reorganized into, merged with, or spun out your company
51
+
52
+ All dollar figures are United States dollars as of 2019. Adjust for them
53
+ inflation according to the United States Bureau of Labor Statistics'
54
+ consumer price index for all urban consumers, United States city average,
55
+ for all items, not seasonally adjusted, with 1982–1984=100 reference base.
56
+
57
+ ## Big Business
58
+
59
+ You may use the software for the benefit of your company:
60
+
61
+ 1. for 128 days after your company stops qualifying under
62
+ [Small Business](#small-business)
63
+
64
+ 2. indefinitely, if the licensor or their legal successor does not offer
65
+ fair, reasonable, and nondiscriminatory terms for a commercial license for
66
+ the software within 32 days of [written request](#how-to-request) and
67
+ negotiate in good faith to conclude a deal
68
+
69
+ ## How to Request
70
+
71
+ If this software includes an address for the licensor or an agent of the
72
+ licensor in a standard place, such as in documentation, software package
73
+ metadata, or an "about" page or screen, try to request a fair commercial
74
+ license at that address. If this package includes both online and offline
75
+ addresses, try online before offline. If you can't deliver a request that
76
+ way, or this software doesn't include any addressees, spend one hour online
77
+ researching an address, recording all your searches and inquiries as you
78
+ go, and try any addresses that you find. If you can't find any addresses,
79
+ or if those addresses also fail, that counts as failure to offer a fair
80
+ commercial license by the licensor under [Big Business](#big-business).
81
+
82
+ ## Fair, Reasonable, and Nondiscriminatory Terms
83
+
84
+ Fair, reasonable, and nondiscriminatory terms may license the software
85
+ perpetually or for a term, and may or may not cover new versions of the
86
+ software. If the licensor advertises license terms and a pricing structure
87
+ for generally available commercial licenses, the licensor proposes license
88
+ terms and a price as advertised, and a customer not affiliated with the
89
+ licensor has bought a commercial license for the software on substantially
90
+ equivalent terms in the past year, the proposal is fair, reasonable, and
91
+ nondiscriminatory.
92
+
93
+ ## Copyright License
94
+
95
+ The licensor grants you a copyright license to do everything with the
96
+ software that would otherwise infringe the licensor's copyright in it for
97
+ any purpose allowed by these terms.
98
+
99
+ ## Notices
100
+
101
+ You must ensure that anyone who gets a copy of any part of the software
102
+ from you also gets a copy of these terms or the URL for them above, as well
103
+ as copies of any plain-text lines beginning with `Required Notice:` that
104
+ the licensor provided with the software. For example:
105
+
106
+ > Required Notice: Copyright Nick Thomas (https://nichoth.com)
107
+
108
+ ## Patent License
109
+
110
+ The licensor grants you a patent license for the software that covers
111
+ patent claims the licensor can license, or becomes able to license, that
112
+ you would infringe by using the software.
113
+
114
+ ## Fair Use
115
+
116
+ You may have "fair use" rights for the software under the law. These terms
117
+ do not limit them.
118
+
119
+ ## No Other Rights
120
+
121
+ These terms do not allow you to sublicense or transfer any of your licenses
122
+ to anyone else, or prevent the licensor from granting licenses to anyone
123
+ else. These terms do not imply any other licenses.
124
+
125
+ ## Patent Defense
126
+
127
+ If you make any written claim that the software infringes or contributes to
128
+ infringement of any patent, your patent license for the software granted
129
+ under these terms ends immediately. If your company makes such a claim,
130
+ your patent license ends immediately for work on behalf of your company.
131
+
132
+ ## Violations
133
+
134
+ The first time you are notified in writing that you have violated any of
135
+ these terms, or done anything with the software not covered by your
136
+ licenses, your licenses can nonetheless continue if you come into full
137
+ compliance with these terms, and take practical steps to correct past
138
+ violations, within 32 days of receiving notice. Otherwise, all your
139
+ licenses end immediately.
140
+
141
+ ## No Liability
142
+
143
+ ***As far as the law allows, the software comes as is, without any warranty
144
+ or condition, and the licensor will not be liable to you for any damages
145
+ arising out of these terms or the use or nature of the software, under any
146
+ kind of legal claim.***
147
+
148
+ ## Definitions
149
+
150
+ The **licensor** is the individual or entity offering these terms, and
151
+ the **software** is the software the licensor makes available under these
152
+ terms.
153
+
154
+ **You** refers to the individual or entity agreeing to these terms.
155
+
156
+ **Your company** is any legal entity, sole proprietorship, or other kind of
157
+ organization that you work for, plus all organizations that have control
158
+ over, are under the control of, or are under common control with that
159
+ organization. **Control** means ownership of substantially all the assets
160
+ of an entity, or the power to direct its management and policies by vote,
161
+ contract, or otherwise. Control can be direct or indirect.
162
+
163
+ **Your licenses** are all the licenses granted to you for the software
164
+ under these terms.
165
+
166
+ **Use** means anything you do with the software requiring one of your
167
+ licenses.
168
+
package/README.md CHANGED
@@ -1,3 +1,313 @@
1
- # Temporary Holding Version
1
+ # substrate-select
2
+ ![tests](https://github.com/substrate-system/select/actions/workflows/nodejs.yml/badge.svg)
3
+ [![types](https://img.shields.io/npm/types/@substrate-system/select?style=flat-square)](README.md)
4
+ [![module](https://img.shields.io/badge/module-ESM%2FCJS-blue?style=flat-square)](README.md)
5
+ [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/select?cache-control=no-cache)](https://packagephobia.com/result?p=@substrate-system/select)
6
+ [![GZip size](https://flat.badgen.net/bundlephobia/minzip/@substrate-system/select)](https://bundlephobia.com/package/@substrate-system/select)
7
+ [![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&style=flat-square)](https://semver.org/)
8
+ [![Common Changelog](https://nichoth.github.io/badge/common-changelog.svg)](./CHANGELOG.md)
9
+ [![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)
2
10
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
11
+
12
+ A native `<select>` with a consistent, themeable look. Write ordinary
13
+ `<option>` and `<optgroup>` children; the component builds a real
14
+ `<select>` around them, so forms, keyboard use, and accessibility work
15
+ the way the browser already does them.
16
+
17
+ [See a live demo](https://substrate-system.github.io/select/)
18
+
19
+ <details><summary><h2>Contents</h2></summary>
20
+
21
+ <!-- toc -->
22
+
23
+ - [Install](#install)
24
+ - [Example](#example)
25
+ * [htm and Preact](#htm-and-preact)
26
+ - [API](#api)
27
+ * [ESM](#esm)
28
+ * [Common JS](#common-js)
29
+ * [Attributes](#attributes)
30
+ * [Options](#options)
31
+ * [Properties](#properties)
32
+ * [Events](#events)
33
+ * [Forms](#forms)
34
+ - [CSS](#css)
35
+ * [Import CSS](#import-css)
36
+ * [Tokens](#tokens)
37
+ * [Browser support](#browser-support)
38
+ * [Avoid a flash of undefined content](#avoid-a-flash-of-undefined-content)
39
+ - [Use](#use)
40
+ * [JS](#js)
41
+ * [HTML](#html)
42
+ * [pre-built](#pre-built)
43
+
44
+ <!-- tocstop -->
45
+
46
+ </details>
47
+
48
+ ## Install
49
+
50
+ ```sh
51
+ npm i -S @substrate-system/select
52
+ ```
53
+
54
+ ## Example
55
+
56
+ ```html
57
+ <form>
58
+ <substrate-select label="Fruit" name="fruit" required>
59
+ <option value="">Choose a fruit</option>
60
+ <optgroup label="Citrus">
61
+ <option value="lemon">Lemon</option>
62
+ <option value="orange" selected>Orange</option>
63
+ </optgroup>
64
+ <option value="apple">Apple</option>
65
+ </substrate-select>
66
+ </form>
67
+
68
+ <script type="module">
69
+ import { SubstrateSelect } from '@substrate-system/select'
70
+
71
+ const el = document.querySelector('substrate-select')
72
+ el.on('change', ev => console.log(ev.detail.value))
73
+ </script>
74
+ ```
75
+
76
+ ### htm and Preact
77
+
78
+ Preact sets `value` as a property, because the element defines one.
79
+
80
+ ```js
81
+ import { html } from 'htm/preact'
82
+ import '@substrate-system/select'
83
+
84
+ function FruitPicker ({ fruit, onChange }) {
85
+ return html`<substrate-select
86
+ label="Fruit"
87
+ name="fruit"
88
+ value=${fruit}
89
+ onsubstrate-select:change=${ev => onChange(ev.detail.value)}
90
+ >
91
+ <option value="lemon">Lemon</option>
92
+ <option value="apple">Apple</option>
93
+ </substrate-select>`
94
+ }
95
+ ```
96
+
97
+ ## API
98
+
99
+ This exposes ESM and common JS via
100
+ [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
101
+
102
+ ### ESM
103
+ ```js
104
+ import { SubstrateSelect } from '@substrate-system/select'
105
+ ```
106
+
107
+ Importing the module registers the `<substrate-select>` element.
108
+
109
+ ### Common JS
110
+ ```js
111
+ require('@substrate-system/select')
112
+ ```
113
+
114
+ ### Attributes
115
+
116
+ | Attribute | Behavior |
117
+ |-----------|----------|
118
+ | `label` | Renders a `<label>` for the select. Changing it updates the label in place; removing it removes the label. |
119
+ | `name`, `disabled`, `required`, `autocomplete`, `form` | Copied to the inner select and kept on the host. |
120
+ | `id` | Moved to the inner select and removed from the host. A generated id is used when absent. |
121
+ | `aria-*` | Moved to the inner select and removed from the host. |
122
+
123
+ `multiple` and `size` are not supported (listbox mode is only
124
+ styleable in Chromium). Setting or removing `id` or an `aria-*`
125
+ attribute on the host after upgrade updates the inner select, so a
126
+ framework can toggle `aria-invalid` or `aria-describedby` for error
127
+ messages. Removing `id` falls back to the generated id.
128
+
129
+ At first render every `aria-*` attribute moves. After that, a newly set
130
+ `aria-*` attribute moves only if it is listed in the exported
131
+ `ARIA_ATTRIBUTES` array. Removing any `aria-*` attribute from the host
132
+ removes it from the select.
133
+
134
+ ### Options
135
+
136
+ Authored `<option>` and `<optgroup>` children are moved into the select
137
+ on first connect, and options appended to the host later are moved to
138
+ the end of the select. Other children present at first connect are
139
+ dropped; non-option children appended later are left in place.
140
+
141
+ A framework that later inserts a node relative to a moved option may
142
+ fail, because that option is no longer a child of the host. Manage
143
+ dynamic option lists through `el.select`.
144
+
145
+ ### Properties
146
+
147
+ - `value` -- read or write the selected value. A value set before the
148
+ element renders is held until an option with that value exists,
149
+ whether it is appended to the host or added through `el.select`, then
150
+ selected, unless a later `value` set or a user pick replaces it.
151
+ Before render, `value` returns the waiting value. Once rendered, the
152
+ select starts with no selection while the value waits (`value` is
153
+ `""`), even if an option was authored `selected`; options added
154
+ after that follow the browser's usual selection rules.
155
+ Options appended to the host in the same tick are moved in before a
156
+ new value is applied. After render, setting a value with no matching
157
+ option leaves `""`.
158
+ - `select` -- the inner `HTMLSelectElement`, or `null` before the first
159
+ render.
160
+ - `label`, `name`, `disabled`, `required` -- reflect the attributes of
161
+ the same name.
162
+
163
+ ### Events
164
+
165
+ Native `change` and `input` events bubble from the inner select
166
+ unchanged. On `change` the element also emits `substrate-select:change`
167
+ with `detail: { value:string }` (`SubstrateSelectChangeDetail`).
168
+
169
+ ```js
170
+ el.addEventListener(SubstrateSelect.event('change'), ev => {
171
+ console.log(ev.detail.value)
172
+ })
173
+ // or
174
+ el.on('change', ev => console.log(ev.detail.value))
175
+ ```
176
+
177
+ Setting `el.value` from code fires neither event, like a native select.
178
+
179
+ ### Forms
180
+
181
+ The select is a light-DOM descendant of the enclosing `<form>`, so
182
+ submission and `FormData` include it with no extra work.
183
+
184
+
185
+ ## CSS
186
+
187
+ ### Import CSS
188
+
189
+ ```js
190
+ import '@substrate-system/select/css'
191
+ ```
192
+
193
+ Or minified:
194
+ ```js
195
+ import '@substrate-system/select/min/css'
196
+ ```
197
+
198
+ ### Tokens
199
+
200
+ The first eight tokens fall back to a shared `--substrate-*` variable,
201
+ then to a default. The last three have only a default.
202
+
203
+ | Token | Falls back to | Default |
204
+ |-------|---------------|---------|
205
+ | `--substrate-select-text` | `--substrate-text` | `black` |
206
+ | `--substrate-select-surface` | `--substrate-surface` | `white` |
207
+ | `--substrate-select-border` | `--substrate-border` | `#9b9b9b` |
208
+ | `--substrate-select-accent` | `--substrate-accent` | `#2563eb` |
209
+ | `--substrate-select-focus` | `--substrate-focus` | `#2563eb` |
210
+ | `--substrate-select-focus-width` | `--substrate-focus-width` | `2px` |
211
+ | `--substrate-select-focus-offset` | `--substrate-focus-offset` | `2px` |
212
+ | `--substrate-select-radius` | `--substrate-radius` | `0` |
213
+ | `--substrate-select-option-hover` | none | `#f3f4f6` |
214
+ | `--substrate-select-checked` | none | `#1d4ed8` |
215
+ | `--substrate-select-shadow` | none | `0 4px 12px #21212114` |
216
+
217
+ `--substrate-select-checked` colors the chosen option's text in the
218
+ picker. It does not follow the accent, so set it too when you change
219
+ the accent (`--substrate-select-accent` or `--substrate-accent`).
220
+
221
+ ```css
222
+ substrate-select {
223
+ --substrate-select-accent: rebeccapurple;
224
+ --substrate-select-checked: rebeccapurple;
225
+ }
226
+ ```
227
+
228
+ ### Browser support
229
+
230
+ The baseline (outlined trigger, chevron, focus and hover states) works
231
+ in every browser. Where `appearance: base-select` is supported, the
232
+ picker is styled too: a rotating chevron, a checkmark on the chosen
233
+ option, and an open transition, which respects reduced motion. Today
234
+ that is Chromium (Chrome and Edge 135+). Safari 27 support is announced
235
+ but unconfirmed in stable, and Firefox has it only behind flags.
236
+ Elsewhere the browser's native picker opens.
237
+
238
+ ### Avoid a flash of undefined content
239
+
240
+ The stylesheet hides `substrate-select` until the browser has defined
241
+ it, so you do not see unstyled markup while the JS loads.
242
+
243
+ That only covers this one element. If your page uses several custom
244
+ elements, hide the whole page until they are all ready, and reveal it
245
+ once:
246
+
247
+ ```html
248
+ <html class="reduce-fouce">
249
+ ```
250
+
251
+ ```css
252
+ html.reduce-fouce { opacity: 0; }
253
+ ```
254
+
255
+ ```js
256
+ await Promise.race([
257
+ Promise.allSettled([
258
+ customElements.whenDefined('substrate-select')
259
+ ]),
260
+ // reveal anyway after two seconds
261
+ new Promise(resolve => { setTimeout(resolve, 2000) })
262
+ ])
263
+
264
+ document.documentElement.classList.remove('reduce-fouce')
265
+ ```
266
+
267
+ Keep the timeout, and add a `<noscript>` override. Without both, a
268
+ component that fails to define leaves the page blank:
269
+
270
+ ```html
271
+ <noscript>
272
+ <style>html.reduce-fouce { opacity: 1 !important; }</style>
273
+ </noscript>
274
+ ```
275
+
276
+ ## Use
277
+ This calls the global function `customElements.define`. Just import, then use
278
+ the tag in your HTML.
279
+
280
+ ### JS
281
+ ```js
282
+ import '@substrate-system/select'
283
+ ```
284
+
285
+ ### HTML
286
+ ```html
287
+ <substrate-select label="Size" name="size">
288
+ <option value="s">Small</option>
289
+ <option value="l">Large</option>
290
+ </substrate-select>
291
+ ```
292
+
293
+ ### pre-built
294
+
295
+ This package exposes minified JS and CSS files too. Copy them to a location that is
296
+ accessible to your web server, then link to them in HTML.
297
+
298
+ #### copy
299
+ ```sh
300
+ cp ./node_modules/@substrate-system/select/dist/index.min.js ./public/substrate-select.min.js
301
+ cp ./node_modules/@substrate-system/select/dist/index.min.css ./public/substrate-select.css
302
+ ```
303
+
304
+ #### HTML
305
+ ```html
306
+ <head>
307
+ <link rel="stylesheet" href="./substrate-select.css">
308
+ </head>
309
+ <body>
310
+ <!-- ... -->
311
+ <script type="module" src="./substrate-select.min.js"></script>
312
+ </body>
313
+ ```