@internetarchive/elements 0.2.1-webdev-8162.0 → 0.2.1-webdev-8777.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/README.md +208 -30
- package/dist/src/elements/ia-button/ia-button.d.ts +41 -3
- package/dist/src/elements/ia-button/ia-button.d.ts.map +1 -1
- package/dist/src/elements/ia-button/ia-button.js +350 -11
- package/dist/src/elements/ia-button/ia-button.js.map +1 -1
- package/dist/src/elements/ia-combo-box/ia-combo-box.d.ts +4 -4
- package/dist/src/elements/ia-combo-box/ia-combo-box.d.ts.map +1 -1
- package/dist/src/elements/ia-combo-box/ia-combo-box.js +21 -13
- package/dist/src/elements/ia-combo-box/ia-combo-box.js.map +1 -1
- package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.d.ts +68 -0
- package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.d.ts.map +1 -0
- package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.js +328 -0
- package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.js.map +1 -0
- package/dist/src/elements/ia-dropdown-search-bar/models.d.ts +17 -0
- package/dist/src/elements/ia-dropdown-search-bar/models.d.ts.map +1 -0
- package/dist/src/elements/ia-dropdown-search-bar/models.js +2 -0
- package/dist/src/elements/ia-dropdown-search-bar/models.js.map +1 -0
- package/dist/src/elements/ia-dropdown-search-bar/search.svg +10 -0
- package/dist/src/elements/ia-otp-form/ia-otp-form.d.ts +21 -0
- package/dist/src/elements/ia-otp-form/ia-otp-form.d.ts.map +1 -0
- package/dist/src/elements/ia-otp-form/ia-otp-form.js +157 -0
- package/dist/src/elements/ia-otp-form/ia-otp-form.js.map +1 -0
- package/dist/src/elements/ia-otp-input/ia-otp-input.d.ts +35 -0
- package/dist/src/elements/ia-otp-input/ia-otp-input.d.ts.map +1 -0
- package/dist/src/elements/ia-otp-input/ia-otp-input.js +217 -0
- package/dist/src/elements/ia-otp-input/ia-otp-input.js.map +1 -0
- package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.d.ts +10 -0
- package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.d.ts.map +1 -0
- package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.js +43 -0
- package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.js.map +1 -0
- package/dist/src/elements/ia-status-indicator/ia-status-indicator.d.ts +4 -1
- package/dist/src/elements/ia-status-indicator/ia-status-indicator.d.ts.map +1 -1
- package/dist/src/elements/ia-status-indicator/ia-status-indicator.js +10 -1
- package/dist/src/elements/ia-status-indicator/ia-status-indicator.js.map +1 -1
- package/dist/src/elements/index.d.ts +3 -2
- package/dist/src/elements/index.d.ts.map +1 -1
- package/dist/src/elements/index.js +3 -2
- package/dist/src/elements/index.js.map +1 -1
- package/dist/src/labs/ia-snow/ia-snow.js +3 -3
- package/dist/src/themes/theme-styles.d.ts.map +1 -1
- package/dist/src/themes/theme-styles.js +94 -0
- package/dist/src/themes/theme-styles.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# 📚 _elements_ 🏛️
|
|
2
2
|
|
|
3
|
+
## Demo
|
|
4
|
+
|
|
5
|
+
<https://internetarchive.github.io/elements>
|
|
6
|
+
|
|
3
7
|
## Installation
|
|
4
8
|
|
|
5
9
|
```zsh
|
|
@@ -16,6 +20,71 @@ import "@internetarchive/elements/ia-button/ia-button";
|
|
|
16
20
|
<ia-button @click=() => alert('Clicked!')>Click Me</ia-button>
|
|
17
21
|
```
|
|
18
22
|
|
|
23
|
+
## Build Dependencies
|
|
24
|
+
|
|
25
|
+
We use SVGs in this repo, which not all build systems support out of the box. Here's how to support SVGs:
|
|
26
|
+
|
|
27
|
+
### Webpack
|
|
28
|
+
|
|
29
|
+
Add this to your Webpack config:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
module: {
|
|
33
|
+
rules: [
|
|
34
|
+
{
|
|
35
|
+
test: /\.svg/,
|
|
36
|
+
type: 'asset/resource',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### @web/test-runner
|
|
43
|
+
|
|
44
|
+
Install rollup image plugins:
|
|
45
|
+
|
|
46
|
+
```shell
|
|
47
|
+
npm i -D @rollup/plugin-image @web/dev-server-rollup
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Update config:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import rollupImage from '@rollup/plugin-image';
|
|
54
|
+
import { rollupAdapter } from '@web/dev-server-rollup';
|
|
55
|
+
|
|
56
|
+
export default ({
|
|
57
|
+
mimeTypes: {
|
|
58
|
+
'**/*.scss': 'js',
|
|
59
|
+
'**/*.css': 'js',
|
|
60
|
+
'**/*.svg': 'js',
|
|
61
|
+
'**/*.json': 'js',
|
|
62
|
+
},
|
|
63
|
+
plugins: [rollupAdapter(rollupImage())],
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Jest
|
|
68
|
+
|
|
69
|
+
Create `SVGMock` file, ie `tests/jest/mocks/svg.js`
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
/**
|
|
73
|
+
* Mock for SVG imports in Jest tests.
|
|
74
|
+
*/
|
|
75
|
+
export class SVGMock {}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Add to Jest config:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
"jest": {
|
|
82
|
+
"moduleNameMapper": {
|
|
83
|
+
"\\.svg$": "<rootDir>/tests/jest/mocks/svg.js",
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
19
88
|
## Development
|
|
20
89
|
|
|
21
90
|
```zsh
|
|
@@ -23,10 +92,41 @@ npm i
|
|
|
23
92
|
npm run dev
|
|
24
93
|
```
|
|
25
94
|
|
|
95
|
+
## Versioning and Publishing
|
|
96
|
+
|
|
97
|
+
### Prerelease Version
|
|
98
|
+
|
|
99
|
+
1. Create prerelease version on your branch:
|
|
100
|
+
1. `npm version prerelease --preid=<some_prefix>`
|
|
101
|
+
2. If you use JIRA, recommend using the ticket number, ie `--preid=webdev-1234`
|
|
102
|
+
3. This will also create a `git` tag
|
|
103
|
+
2. Push the tag that was created in the `npm version` step
|
|
104
|
+
3. Publish prerelease to npm:
|
|
105
|
+
1. Go to the [Element release page](https://github.com/internetarchive/elements/releases)
|
|
106
|
+
2. Tap `Draft a new release` button
|
|
107
|
+
3. Select the tag you created
|
|
108
|
+
4. Tap `Generate release notes`
|
|
109
|
+
5. Select `Set as a pre-release`
|
|
110
|
+
6. Tap `Publish release`
|
|
111
|
+
|
|
112
|
+
### Release Version
|
|
113
|
+
|
|
114
|
+
1. Use [Semantic Versioning](https://semver.org) to determine release number
|
|
115
|
+
2. On the `main` branch:
|
|
116
|
+
1. Run `npm version [major | minor | patch]`
|
|
117
|
+
2. `git push && git push --tags`
|
|
118
|
+
3. Publish release to npm:
|
|
119
|
+
1. Go to the [Element release page](https://github.com/internetarchive/elements/releases)
|
|
120
|
+
2. Tap `Draft a new release` button
|
|
121
|
+
3. Select the tag you created
|
|
122
|
+
4. Tap `Generate release notes`
|
|
123
|
+
5. Select `Set as the latest release`
|
|
124
|
+
6. Tap `Publish release`
|
|
125
|
+
|
|
26
126
|
## Adding a Component
|
|
27
127
|
|
|
28
128
|
### Structure
|
|
29
|
-
Each component has its own directory in `src/elements` (or `src/labs` if it's still in development). The basic structure looks like this, though components can have additional files and directories if
|
|
129
|
+
Each component has its own directory in `src/elements` (or `src/labs` if it's still in development). The basic structure looks like this, though components can have additional files and directories if needed. Take a look at other elements to see what they each contain.
|
|
30
130
|
```
|
|
31
131
|
src
|
|
32
132
|
- elements
|
|
@@ -42,61 +142,139 @@ To demo your component, we have a component catalog that you can add your demo t
|
|
|
42
142
|
|
|
43
143
|
We have a story template you can use for consistency. [More info on `story-template`](#story-template). The easiest way to use this is to copy an existing story and modify it for your needs.
|
|
44
144
|
|
|
45
|
-
|
|
145
|
+
Your story will be discovered by `/demo/app-root.ts` and added to the page.
|
|
46
146
|
|
|
47
147
|
#### Story Template<a id="story-template"></a>
|
|
48
148
|
|
|
49
149
|
The story template is a component you can use in your story to demo your component. This lets us present them in a consistent way.
|
|
50
150
|
|
|
51
|
-
It has
|
|
151
|
+
It has a few main configurations:
|
|
52
152
|
|
|
53
153
|
*Properties*
|
|
54
154
|
- `elementTag` (_string_) your component's name, ie `ia-button`
|
|
55
|
-
- `exampleUsage` (_string_) your element's example usage, displays it with syntax highlighting
|
|
56
155
|
- `labs` (_boolean_) if your component is in `labs` to update links
|
|
156
|
+
- `styleInputSettings` (_StyleInputSettings array_) the style options to display, in the appropriate format
|
|
157
|
+
- `propInputSettings` (_PropInputSettings array_) the prop options to display, in the appropriate format
|
|
158
|
+
|
|
159
|
+
**Note:** If the type of prop input you want to use isn't yet available in the `propInputSettings` options,
|
|
160
|
+
you can instead slot in custom property settings by using `slot="settings"`, adding a button to apply the
|
|
161
|
+
properties, and passing in a `customExampleUsage` (see `ia-snow-story.ts` for a sample implementation).
|
|
57
162
|
|
|
58
163
|
*Slots*
|
|
59
164
|
- `demo` put your component demo in here
|
|
60
|
-
- `settings` put your component settings in here
|
|
61
165
|
|
|
62
166
|
Here's an example:
|
|
63
167
|
```typescript
|
|
64
168
|
import '@demo/story-template';
|
|
169
|
+
|
|
170
|
+
// Style options to display
|
|
171
|
+
const styleInputSettings: StyleInputSettings[] = [
|
|
172
|
+
{
|
|
173
|
+
label: 'Button BG color',
|
|
174
|
+
cssVariable: '--button-background-color',
|
|
175
|
+
defaultValue: 'blue', // Should match the actual fallback value for the variable
|
|
176
|
+
inputType: 'color',
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
// Prop options to display
|
|
181
|
+
const propInputSettings: PropInputSettings[] = [
|
|
182
|
+
{
|
|
183
|
+
label: 'Mode',
|
|
184
|
+
inputType: 'radio',
|
|
185
|
+
propertyName: 'mode', // Should match the name of the property from its @property() declaration
|
|
186
|
+
radioOptions: ['primary', 'secondary', 'danger'],
|
|
187
|
+
defaultValue: 'primary', // Should match the actual default value from the @property() declaration, if any
|
|
188
|
+
},
|
|
189
|
+
]
|
|
65
190
|
...
|
|
66
191
|
render() {
|
|
67
192
|
return html`
|
|
68
|
-
<story-template
|
|
193
|
+
<story-template
|
|
194
|
+
elementTag="ia-button"
|
|
195
|
+
elementClassName="IAButton"
|
|
196
|
+
.styleInputData=${{settings: this.styleInputSettings}}
|
|
197
|
+
.propInputData=${{settings: this.propInputSettings}}
|
|
198
|
+
>
|
|
69
199
|
<div slot="demo">
|
|
70
|
-
<ia-button @click=${() => alert('Button clicked!')}
|
|
71
|
-
|
|
72
|
-
>
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<div slot="settings">
|
|
76
|
-
<table>
|
|
77
|
-
<tr>
|
|
78
|
-
<td>Color</td>
|
|
79
|
-
<td><input type="color" value="#007bff" id="color" /></td>
|
|
80
|
-
</tr>
|
|
81
|
-
</table>
|
|
82
|
-
<button @click=${this.apply}>Apply</button>
|
|
200
|
+
<ia-button @click=${() => alert('Button clicked!')}>
|
|
201
|
+
Click Me
|
|
202
|
+
</ia-button>
|
|
83
203
|
</div>
|
|
84
204
|
</story-template>
|
|
85
205
|
`;
|
|
86
206
|
}
|
|
207
|
+
```
|
|
87
208
|
|
|
88
|
-
|
|
89
|
-
// be displayed with syntax highlighting
|
|
90
|
-
// can be dynamic
|
|
91
|
-
private get exampleUsage(): string {
|
|
92
|
-
return `<ia-button @click=\${() => alert('Button clicked!')}>
|
|
93
|
-
Click Me
|
|
94
|
-
</ia-button>`;
|
|
95
|
-
}
|
|
209
|
+
### Styling
|
|
96
210
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
211
|
+
For styling, our components use a series of rational CSS variable fallbacks to ensure:
|
|
212
|
+
1. All components render out of the box with reasonable defaults for colors, sizing, etc.
|
|
213
|
+
2. Customizable styles can be adjusted by the consumer by setting a CSS variable at the component or global level
|
|
214
|
+
3. The available variables are easy to find in the component file and visible in the story
|
|
215
|
+
|
|
216
|
+
#### Setting up styles
|
|
217
|
+
|
|
218
|
+
1. In the component's CSS, include the elements-wide `themeStyles` defaults
|
|
219
|
+
```
|
|
220
|
+
import themeStyles from '@src/themes/theme-styles';
|
|
221
|
+
...
|
|
222
|
+
static get styles(): CSSResultGroup {
|
|
223
|
+
return [
|
|
224
|
+
themeStyles,
|
|
225
|
+
css`
|
|
226
|
+
```
|
|
227
|
+
2. Check the theme styles to see if an existing theme variable exists you can use as a default, i.e. for an error message color you could use `--color-danger` if no variable exists but the style you want seems fairly reusable, see [Creating a new theme style](#creating-a-new-theme-style) below. If the variable is _not_ reusable, see [Non-reusable styles](#non-reusable-styles) below.
|
|
228
|
+
3. In the component, create a private CSS variable in the top-level `:host` section to make your chosen variable obvious to consumers, and then use this private variable wherever you need the value
|
|
229
|
+
```
|
|
230
|
+
css`
|
|
231
|
+
:host {
|
|
232
|
+
--color-danger--: var(--color-danger);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.error-msg {
|
|
236
|
+
color: var(--color-danger--);
|
|
237
|
+
```
|
|
238
|
+
4. In the component's story, add the variable you chose in its full `ia-theme-` form, with its default fallback value, to the story `styleInputData`
|
|
239
|
+
```
|
|
240
|
+
const styleInputSettings: StyleInputSettings[] = [
|
|
241
|
+
{
|
|
242
|
+
label: 'Error color',
|
|
243
|
+
cssVariable: '--ia-theme-color-danger',
|
|
244
|
+
defaultValue: '#e51c23',
|
|
245
|
+
inputType: 'color',
|
|
246
|
+
},
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Creating a new theme style
|
|
250
|
+
While working on a component, you may realize that a customizable style you need doesn't already have an associated variable in `theme-styles.ts`. If this happens, you can follow the following steps to add one:
|
|
251
|
+
1. Select a rational default value for the style, and add it to the defaults section at the top of the file:
|
|
252
|
+
```
|
|
253
|
+
--default-font-size-xs: 0.625rem /* 10px with 16px root font size */
|
|
254
|
+
```
|
|
255
|
+
2. Name the variable and add it to the adjustable styles list with the following structure:
|
|
256
|
+
```
|
|
257
|
+
--font-size-xs: var(--ia-theme-font-size-xs, var(--default-font-size-xs));
|
|
258
|
+
```
|
|
259
|
+
3. Use the variable as needed in your component and its story, following the steps in the [Setting up styles](#setting-up-styles) section
|
|
260
|
+
|
|
261
|
+
#### Non-reusable styles
|
|
262
|
+
|
|
263
|
+
If you have a variable that you want to make customizable but you're sure is only applicable for this component and wouldn't be of use elsewhere, you can add it as a private variable to `:host`, setting an explicit fallback within the component and prefixing it with the component to avoid variable overlap.
|
|
264
|
+
```
|
|
265
|
+
--my-component-max-height--: var(--my-component-max-height, 250px);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### Other styles
|
|
269
|
+
|
|
270
|
+
For any styles that you won't be exposing to consumers via the story, you can proceed as usual, but we recommend adding a named `part` to areas of the component, such as nested elements, you imagine someone may want to further style directly.
|
|
271
|
+
```
|
|
272
|
+
<div class="indicator">
|
|
273
|
+
<ia-status-indicator
|
|
274
|
+
part="status-indicator"
|
|
275
|
+
.mode=${this.validationStatus}
|
|
276
|
+
></ia-status-indicator>
|
|
277
|
+
</div>
|
|
100
278
|
```
|
|
101
279
|
|
|
102
280
|
## Component Inventory
|
|
@@ -1,9 +1,47 @@
|
|
|
1
|
-
import { LitElement,
|
|
1
|
+
import { LitElement, TemplateResult, CSSResultGroup, PropertyValues } from 'lit';
|
|
2
|
+
import '../ia-status-indicator/ia-status-indicator.js';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Renders a standardized button built off the ia-button styling and the activity indicator, with the option to show
|
|
5
|
+
* a loading indicator instead of the text or to customize the text, and the ability to pass in any
|
|
6
|
+
* function to run on click.
|
|
7
|
+
*
|
|
8
|
+
* Designed to behave exactly like a native type="submit" or type="reset" button if either type is supplied,
|
|
9
|
+
* i.e. for an <ia-button type="submit" @click=${doSideEffects}></ia-button>,
|
|
10
|
+
* whether the form is submitted via enter or by clicking the button directly, the button will always
|
|
11
|
+
* run doSideEffects() and then submit the form.
|
|
4
12
|
*/
|
|
5
13
|
export declare class IAButton extends LitElement {
|
|
6
|
-
|
|
14
|
+
mode: 'primary' | 'secondary' | 'danger' | 'warning' | 'disabled' | 'transparent' | 'custom' | 'link' | 'danger-link';
|
|
15
|
+
loading: boolean;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
loadingText: string;
|
|
18
|
+
type: 'button' | 'submit' | 'reset';
|
|
19
|
+
href?: string;
|
|
20
|
+
openLinksNewTab: boolean;
|
|
21
|
+
render(): TemplateResult;
|
|
22
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
23
|
+
private get buttonTemplate();
|
|
24
|
+
private get buttonTextTemplate();
|
|
25
|
+
private get loadingStateTemplate();
|
|
26
|
+
/** Sets up or removes button type emulation as needed */
|
|
27
|
+
private setButtonTypeEmulation;
|
|
28
|
+
/**
|
|
29
|
+
* Triggers form actions (submit/reset) on click, if desired
|
|
30
|
+
* and if actions not already in progress
|
|
31
|
+
*/
|
|
32
|
+
private handleComponentClick;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a hidden button to the light DOM to
|
|
35
|
+
* emulate native reset/submit button behavior.
|
|
36
|
+
*
|
|
37
|
+
* Used for:
|
|
38
|
+
* - Submitting/resetting the form (on behalf of handleComponentClick)
|
|
39
|
+
* - Activating any component click events if form is submitted with the enter key
|
|
40
|
+
* (via handleFormActions)
|
|
41
|
+
*/
|
|
42
|
+
private addHiddenButton;
|
|
43
|
+
/** Triggers the component's click event manually to prevent extra submission/reset */
|
|
44
|
+
private handleFormActions;
|
|
7
45
|
static get styles(): CSSResultGroup;
|
|
8
46
|
}
|
|
9
47
|
//# sourceMappingURL=ia-button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ia-button.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-button/ia-button.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ia-button.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-button/ia-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,cAAc,EACd,cAAc,EAEd,cAAc,EAEf,MAAM,KAAK,CAAC;AAKb,OAAO,4CAA4C,CAAC;AAEpD;;;;;;;;;GASG;AACH,qBACa,QAAS,SAAQ,UAAU;IAEV,IAAI,EAC5B,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,GACT,UAAU,GACV,aAAa,GACb,QAAQ,GACR,MAAM,GACN,aAAa,CAAa;IAGD,OAAO,EAAE,OAAO,CAAS;IAGzB,QAAQ,EAAE,OAAO,CAAS;IAG3B,WAAW,EAAE,MAAM,CAAM;IAGV,IAAI,EAC3C,QAAQ,GACR,QAAQ,GACR,OAAO,CAAY;IAGK,IAAI,CAAC,EAAE,MAAM,CAAC;IAGb,eAAe,EAAE,OAAO,CAAS;IAE9D,MAAM,IAAI,cAAc;IAaxB,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAOnD,OAAO,KAAK,cAAc,GAUzB;IAGD,OAAO,KAAK,kBAAkB,GAE7B;IAGD,OAAO,KAAK,oBAAoB,GAQ/B;IAED,yDAAyD;IACzD,OAAO,CAAC,sBAAsB;IAc9B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAevB,sFAAsF;IACtF,OAAO,CAAC,iBAAiB;IAwBzB,MAAM,KAAK,MAAM,IAAI,cAAc,CAkNlC;CACF"}
|