@felleslosninger/minid-elements 0.0.140 → 0.1.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 +69 -4
- package/dist/components/alert.component.d.ts +6 -4
- package/dist/components/alert.component.d.ts.map +1 -1
- package/dist/components/alert.js +33 -61
- package/dist/components/alert.js.map +1 -1
- package/dist/components/button.component.d.ts +1 -1
- package/dist/components/checkbox.component.d.ts +1 -2
- package/dist/components/checkbox.component.d.ts.map +1 -1
- package/dist/components/checkbox.js +25 -55
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/code-input-old.component.d.ts +1 -1
- package/dist/components/code-input-old.js +1 -1
- package/dist/components/code-input.component.d.ts +1 -1
- package/dist/components/code-input.component.d.ts.map +1 -1
- package/dist/components/code-input.js +232 -94
- package/dist/components/code-input.js.map +1 -1
- package/dist/components/combobox.component.d.ts +1 -1
- package/dist/components/countdown.component.d.ts +1 -1
- package/dist/components/dialog.component.d.ts +1 -1
- package/dist/components/dropdown.component.d.ts +1 -1
- package/dist/components/heading.component.d.ts +1 -1
- package/dist/components/heading.component.d.ts.map +1 -1
- package/dist/components/heading.js +1 -11
- package/dist/components/heading.js.map +1 -1
- package/dist/components/helptext.component.d.ts +1 -1
- package/dist/components/label.component.d.ts +1 -1
- package/dist/components/label.component.d.ts.map +1 -1
- package/dist/components/label.js +3 -12
- package/dist/components/label.js.map +1 -1
- package/dist/components/link.component.d.ts +1 -1
- package/dist/components/link.js +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/menu-item.component.d.ts +1 -1
- package/dist/components/menu.component.d.ts +1 -1
- package/dist/components/paragraph.component.d.ts +1 -1
- package/dist/components/paragraph.component.d.ts.map +1 -1
- package/dist/components/paragraph.js +2 -8
- package/dist/components/paragraph.js.map +1 -1
- package/dist/components/phone-input.component.d.ts +15 -3
- package/dist/components/phone-input.component.d.ts.map +1 -1
- package/dist/components/phone-input.js +37 -6
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popup.component.d.ts +1 -1
- package/dist/components/qr-code.component.d.ts +1 -1
- package/dist/components/radio-button.component.d.ts +1 -1
- package/dist/components/radio-group.component.d.ts +1 -1
- package/dist/components/radio.component.d.ts +1 -1
- package/dist/components/radio.component.d.ts.map +1 -1
- package/dist/components/radio.js +12 -16
- package/dist/components/radio.js.map +1 -1
- package/dist/components/search.component.d.ts +11 -4
- package/dist/components/search.component.d.ts.map +1 -1
- package/dist/components/search.js +75 -31
- package/dist/components/search.js.map +1 -1
- package/dist/components/spinner.component.d.ts +1 -1
- package/dist/components/step-indicator.component.d.ts +1 -1
- package/dist/components/textfield.component.d.ts +2 -2
- package/dist/components/textfield.component.d.ts.map +1 -1
- package/dist/components/textfield.js +66 -82
- package/dist/components/textfield.js.map +1 -1
- package/dist/components/tooltip.component.d.ts +1 -1
- package/dist/components/validation-message.component.d.ts +1 -1
- package/dist/controllers/lang.controller.d.ts +14 -0
- package/dist/controllers/lang.controller.d.ts.map +1 -0
- package/dist/designsystemet-tailwind.css +355 -297
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lang.controller-P4W-9ipy.js +32 -0
- package/dist/lang.controller-P4W-9ipy.js.map +1 -0
- package/dist/styles.css +5 -0
- package/dist/theme.css +1155 -0
- package/dist/utilities/lang.d.ts +6 -0
- package/dist/utilities/lang.d.ts.map +1 -0
- package/dist/utilities/lang.js +18 -0
- package/dist/utilities/lang.js.map +1 -0
- package/dist/utilities/translations.d.ts +42 -0
- package/dist/utilities/translations.d.ts.map +1 -0
- package/dist/utilities/translations.js +45 -0
- package/dist/utilities/translations.js.map +1 -0
- package/package.json +34 -16
package/README.md
CHANGED
|
@@ -16,15 +16,62 @@ or
|
|
|
16
16
|
yarn add @felleslosninger/minid-elements
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## CSS Setup
|
|
20
|
+
|
|
21
|
+
minid-elements uses Tailwind CSS v4 and CSS cascade layers internally. To prevent style conflicts, you must declare the layer order **before** importing Tailwind in your global stylesheet:
|
|
22
|
+
|
|
23
|
+
```css
|
|
24
|
+
/* Establish layer order before @import 'tailwindcss', so ds.* layers sit
|
|
25
|
+
between base and utilities rather than after utilities. */
|
|
26
|
+
@layer theme, base, ds.theme, ds.base, ds.components, components, utilities;
|
|
27
|
+
@import 'tailwindcss';
|
|
28
|
+
@import '@felleslosninger/minid-elements/styles';
|
|
29
|
+
@source '../../node_modules/@felleslosninger/minid-elements/dist';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The stylesheet link in your HTML must have the `data-mid-tailwind` attribute so the components can resolve scoped styles correctly:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<link rel="stylesheet" href="./styles/tailwind.css" data-mid-tailwind />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### CSS entrypoints
|
|
39
|
+
|
|
40
|
+
| Import path | File | Description |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `@felleslosninger/minid-elements/styles` | `dist/styles.css` | Component styles |
|
|
43
|
+
| `@felleslosninger/minid-elements/theme` | `dist/theme.css` | Design tokens / theme |
|
|
44
|
+
| `@felleslosninger/minid-elements/globals` | `dist/index.css` | Global base styles |
|
|
45
|
+
|
|
19
46
|
## Usage
|
|
20
47
|
|
|
21
48
|
Import the desired components into your project:
|
|
22
49
|
|
|
23
|
-
```
|
|
50
|
+
```ts
|
|
24
51
|
import '@felleslosninger/minid-elements/button';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```html
|
|
25
55
|
<mid-button variant="primary">Click me</mid-button>
|
|
26
56
|
```
|
|
27
57
|
|
|
58
|
+
### Translations
|
|
59
|
+
|
|
60
|
+
Built-in UI labels (e.g. "Clear", "Show password", "Open country selector") are available in Norwegian Bokmål, Nynorsk, Northern Sami, and English. Components pick up the page language automatically via the `lang` attribute.
|
|
61
|
+
|
|
62
|
+
To override or add translations for a language:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { registerTranslations } from '@felleslosninger/minid-elements';
|
|
66
|
+
|
|
67
|
+
registerTranslations('en', {
|
|
68
|
+
clear: 'Remove',
|
|
69
|
+
showPassword: 'Reveal password',
|
|
70
|
+
hidePassword: 'Conceal password',
|
|
71
|
+
openCountrySelector: 'Choose country',
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
28
75
|
## CDN Usage
|
|
29
76
|
|
|
30
77
|
Alternatively, you can use MinId Elements directly from our CDN. Here's an example of how to include the components in your HTML file:
|
|
@@ -66,9 +113,27 @@ View the complete component documentation and examples in our Storybook:
|
|
|
66
113
|
If you're contributing to this project, follow these steps:
|
|
67
114
|
|
|
68
115
|
1. Clone the repository.
|
|
69
|
-
2. Install dependencies: `
|
|
70
|
-
3.
|
|
71
|
-
4.
|
|
116
|
+
2. Install dependencies: `pnpm install`.
|
|
117
|
+
3. Build the project: `pnpm run build`.
|
|
118
|
+
4. Run the development server: `pnpm run storybook:dev`.
|
|
119
|
+
|
|
120
|
+
## Publishing
|
|
121
|
+
|
|
122
|
+
This project uses [changesets](https://github.com/changesets/changesets) for versioning and publishing.
|
|
123
|
+
|
|
124
|
+
### Adding a changeset
|
|
125
|
+
|
|
126
|
+
When you make a change that should be released, add a changeset:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pnpm changeset
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Follow the prompts to select the bump type (patch, minor, or major) and describe the change. This creates a markdown file in the `.changeset/` directory that should be committed with your PR.
|
|
133
|
+
|
|
134
|
+
### Releasing
|
|
135
|
+
|
|
136
|
+
When PRs with changesets are merged to `main`, the changesets action will automatically create a "Version Packages" PR that bumps versions and updates the changelog. Merging that PR triggers the actual publish to npm and deploys the new version to the CDN.
|
|
72
137
|
|
|
73
138
|
## Contributing
|
|
74
139
|
|
|
@@ -51,10 +51,12 @@ export declare class MinidAlert extends MinidAlert_base {
|
|
|
51
51
|
*/
|
|
52
52
|
elevated: boolean;
|
|
53
53
|
/**
|
|
54
|
-
* Sets the `aria-
|
|
55
|
-
*
|
|
54
|
+
* Sets the `aria-live` attribute on the alert host element.
|
|
55
|
+
* Prefer wrapping the alert in a `role="alert"` or `aria-live` container instead.
|
|
56
|
+
* Use `"polite"` for non-urgent updates and `"assertive"` for time-sensitive ones.
|
|
57
|
+
* Defaults to `"off"`.
|
|
56
58
|
*/
|
|
57
|
-
|
|
59
|
+
arialive: 'polite' | 'assertive' | 'off';
|
|
58
60
|
private remainingTime;
|
|
59
61
|
private notificationContent?;
|
|
60
62
|
firstUpdated(): void;
|
|
@@ -77,7 +79,7 @@ export declare class MinidAlert extends MinidAlert_base {
|
|
|
77
79
|
* calling this method again. The returned promise will resolve after the alert is hidden.
|
|
78
80
|
*/
|
|
79
81
|
toast(content: MinidAlert['notificationContent'], duration?: number, severity?: MinidAlert['severity'], closable?: boolean): Promise<void>;
|
|
80
|
-
render(): import('lit
|
|
82
|
+
render(): import('lit').TemplateResult<1>;
|
|
81
83
|
}
|
|
82
84
|
export {};
|
|
83
85
|
//# sourceMappingURL=alert.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert.component.d.ts","sourceRoot":"","sources":["../../src/components/alert.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAW,MAAM,KAAK,CAAC;AAIhD,OAAO,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"alert.component.d.ts","sourceRoot":"","sources":["../../src/components/alert.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAW,MAAM,KAAK,CAAC;AAIhD,OAAO,uBAAuB,CAAC;AAS/B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,UAAU,CAAC;KACzB;CACF;;AAMD;;;;;;;;;;;;;GAaG;AACH,qBACa,UAAW,SAAQ,eAAkB;IAChD,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,qBAAqB,CAAC,CAAS;IAGvC,OAAO,CAAC,IAAI,CAAe;IAE3B;;;OAGG;IAEH,IAAI,UAAS;IAEb;;OAEG;IAEH,QAAQ,UAAS;IAEjB;;;;OAIG;IAEH,QAAQ,SAAY;IAEpB;;OAEG;IAEH,QAAQ,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAU;IAE7D;;OAEG;IAEH,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAEhC;;OAEG;IAEH,QAAQ,UAAS;IAEjB;;;;;OAKG;IAEH,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,KAAK,CAAS;IAGjD,OAAO,CAAC,aAAa,CAAiB;IAGtC,OAAO,CAAC,mBAAmB,CAAC,CAI1B;IAEF,YAAY;IAIZ,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,cAAc;IAahB,gBAAgB;IAwCtB,oBAAoB;IAIpB;;OAEG;IACG,IAAI;IASV;;OAEG;IACG,IAAI;IASV;;;;OAIG;IACG,KAAK,CACT,OAAO,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,EACjC,QAAQ,UAAO;IA6DR,MAAM;CAqEhB"}
|
package/dist/components/alert.js
CHANGED
|
@@ -3,7 +3,6 @@ import { query, property, state, customElement } from "lit/decorators.js";
|
|
|
3
3
|
import { classMap } from "lit/directives/class-map.js";
|
|
4
4
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
5
5
|
import "./icon/icon.js";
|
|
6
|
-
import { ifDefined } from "lit/directives/if-defined.js";
|
|
7
6
|
import { watch } from "../internal/watch.js";
|
|
8
7
|
import { getAnimation, setDefaultAnimation } from "../utilities/animation-registry.js";
|
|
9
8
|
import { waitForEvent } from "../internal/event.js";
|
|
@@ -30,6 +29,7 @@ let MinidAlert = class extends styled(LitElement) {
|
|
|
30
29
|
this.severity = "info";
|
|
31
30
|
this.size = "md";
|
|
32
31
|
this.elevated = false;
|
|
32
|
+
this.arialive = "off";
|
|
33
33
|
this.remainingTime = this.duration;
|
|
34
34
|
}
|
|
35
35
|
firstUpdated() {
|
|
@@ -173,54 +173,24 @@ let MinidAlert = class extends styled(LitElement) {
|
|
|
173
173
|
const warning = this.severity === "warning";
|
|
174
174
|
const info = this.severity === "info";
|
|
175
175
|
const success = this.severity === "success";
|
|
176
|
-
const sm = this.size === "sm";
|
|
177
|
-
const md = this.size === "md";
|
|
178
|
-
const lg = this.size === "lg";
|
|
179
|
-
const iconName = danger && "xmark-octagon-fill" || warning && "exclamationmark-triangle-fill" || success && "checkmark-circle-fill" || "information-square-fill";
|
|
180
|
-
this.iconlabel ??= danger && "Feil" || warning && "Advarsel" || success && "Suksess" || "Informasjon";
|
|
181
176
|
return html`
|
|
182
177
|
<div
|
|
183
178
|
part="base"
|
|
184
|
-
class="
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
"text-body-lg": lg,
|
|
188
|
-
"bg-danger-surface-tinted": danger,
|
|
189
|
-
"bg-info-surface-tinted": info,
|
|
190
|
-
"bg-success-surface-tinted": success,
|
|
191
|
-
"bg-warning-surface-tinted": warning,
|
|
192
|
-
"border-danger": danger,
|
|
193
|
-
"border-info": info,
|
|
194
|
-
"border-success": success,
|
|
195
|
-
"border-warning": warning,
|
|
196
|
-
"text-danger": danger,
|
|
197
|
-
"text-info": info,
|
|
198
|
-
"text-success": success,
|
|
199
|
-
"text-warning": warning,
|
|
200
|
-
"shadow-md": this.elevated
|
|
201
|
-
})} grid grid-cols-[auto_1fr_auto] gap-2 rounded border p-6"
|
|
179
|
+
class="ds-alert"
|
|
180
|
+
data-size="${this.size}"
|
|
181
|
+
data-color="${this.severity}"
|
|
202
182
|
@mouseenter=${this.pauseAutoHide}
|
|
203
183
|
@mouseleave=${this.resumeAutoHide}
|
|
204
184
|
>
|
|
205
|
-
<
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
alt=${ifDefined(this.iconlabel)}
|
|
215
|
-
></mid-icon>
|
|
216
|
-
<div aria-live="polite">
|
|
217
|
-
<slot>
|
|
218
|
-
${!this.notificationContent?.title ? nothing : html`<h2 class="text-heading-xs">
|
|
219
|
-
${this.notificationContent?.title}
|
|
220
|
-
</h2>`}
|
|
221
|
-
${this.notificationContent?.message}
|
|
222
|
-
${!this.notificationContent?.details ? nothing : html`<div
|
|
223
|
-
class="${classMap({
|
|
185
|
+
<div style="display: grid; grid-template-columns: 1fr ${this.closable ? "auto" : ""};">
|
|
186
|
+
<div aria-live="${this.arialive}">
|
|
187
|
+
<slot>
|
|
188
|
+
${!this.notificationContent?.title ? nothing : html`<h2 class="text-heading-xs">
|
|
189
|
+
${this.notificationContent?.title}
|
|
190
|
+
</h2>`}
|
|
191
|
+
${this.notificationContent?.message}
|
|
192
|
+
${!this.notificationContent?.details ? nothing : html`<div
|
|
193
|
+
class="${classMap({
|
|
224
194
|
"border-danger": danger,
|
|
225
195
|
"border-info": info,
|
|
226
196
|
"border-success": success,
|
|
@@ -230,16 +200,16 @@ let MinidAlert = class extends styled(LitElement) {
|
|
|
230
200
|
"bg-success-surface-hover": success,
|
|
231
201
|
"bg-warning-surface-hover": warning
|
|
232
202
|
})} text-body-sm mt-0.5 border-l-4 p-3"
|
|
233
|
-
>
|
|
234
|
-
<pre class="break-all whitespace-pre-wrap">
|
|
235
|
-
${this.notificationContent?.details}</pre
|
|
236
203
|
>
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
204
|
+
<pre class="break-all whitespace-pre-wrap">
|
|
205
|
+
${this.notificationContent?.details}</pre
|
|
206
|
+
>
|
|
207
|
+
</div>`}
|
|
208
|
+
</slot>
|
|
209
|
+
</div>
|
|
210
|
+
${this.closable ? html`
|
|
211
|
+
<button
|
|
212
|
+
class="${classMap({
|
|
243
213
|
"text-info-subtle": info,
|
|
244
214
|
"text-danger-subtle": danger,
|
|
245
215
|
"text-success-subtle": success,
|
|
@@ -248,13 +218,15 @@ ${this.notificationContent?.details}</pre
|
|
|
248
218
|
"hover:bg-info-surface-hover": info,
|
|
249
219
|
"hover:bg-success-surface-hover": success,
|
|
250
220
|
"hover:bg-warning-surface-hover": warning
|
|
251
|
-
})}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
221
|
+
})} flex rounded p-2"
|
|
222
|
+
style="align-self: start; justify-self: end;"
|
|
223
|
+
@click="${this.hide}"
|
|
224
|
+
aria-label="Dismiss alert"
|
|
225
|
+
>
|
|
226
|
+
<mid-icon class="size-6" name="xmark"> </mid-icon>
|
|
227
|
+
</button>
|
|
228
|
+
` : nothing}
|
|
229
|
+
</div>
|
|
258
230
|
</div>
|
|
259
231
|
`;
|
|
260
232
|
}
|
|
@@ -281,8 +253,8 @@ __decorateClass([
|
|
|
281
253
|
property({ type: Boolean })
|
|
282
254
|
], MinidAlert.prototype, "elevated", 2);
|
|
283
255
|
__decorateClass([
|
|
284
|
-
property({
|
|
285
|
-
], MinidAlert.prototype, "
|
|
256
|
+
property({ reflect: true })
|
|
257
|
+
], MinidAlert.prototype, "arialive", 2);
|
|
286
258
|
__decorateClass([
|
|
287
259
|
state()
|
|
288
260
|
], MinidAlert.prototype, "remainingTime", 2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert.js","sources":["../../src/components/alert.component.ts"],"sourcesContent":["import { html, LitElement, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styled } from '../mixins/tailwind.mixin.ts';\nimport './icon/icon.component';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { watch } from '../internal/watch';\nimport {\n getAnimation,\n setDefaultAnimation,\n} from '../utilities/animation-registry';\nimport { waitForEvent } from '../internal/event';\nimport { animateTo, stopAnimations } from '../internal/animate';\nimport { type MidIconName } from '../types/icon-name';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-alert': MinidAlert;\n }\n}\n\nconst toastStack = Object.assign(document.createElement('div'), {\n className: 'mid-toast-stack',\n});\n\n/**\n * Alerts need to have the `open` attribute to be displayed\n * @csspart base - Select the base of the alert\n *\n * @event mid-show - Emitted when the alert opens.\n * @event mid-after-show - Emitted after the alert opens and all animations are complete.\n * @event mid-hide - Emitted when the alert closes.\n * @event mid-after-hide - Emitted after the alert closes and all animations are complete.\n *\n * @slot -- The default slot for the content of the alert\n *\n * @animation alert.show - The animation to use when showing the alert.\n * @animation alert.hide - The animation to use when hiding the alert.\n */\n@customElement('mid-alert')\nexport class MinidAlert extends styled(LitElement) {\n private autoHideTimeout?: number;\n private remainingTimeInterval?: number;\n\n @query('[part~=\"base\"]')\n private base!: HTMLElement;\n\n /**\n * Indicates whether or not the alert is open. You can toggle this attribute to show and hide the alert, or you can\n * use the `show()` and `hide()` methods and this attribute will reflect the alert's open state.\n */\n @property({ type: Boolean, reflect: true })\n open = false;\n\n /**\n * Enables a close button that allows the user to dismiss the alert.\n */\n @property({ type: Boolean, reflect: true })\n closable = false;\n\n /**\n * The length of time, in milliseconds, the alert will show before closing itself. If the user interacts with\n * the alert before it closes (e.g. moves the mouse over it), the timer will restart. Defaults to `Infinity`, meaning\n * the alert will not close on its own.\n */\n @property({ type: Number })\n duration = Infinity;\n\n /**\n * Sets color and icon according to severity\n */\n @property({ reflect: true })\n severity: 'warning' | 'info' | 'danger' | 'success' = 'info';\n\n /**\n * Sets size of icon, padding and font-size.\n */\n @property({ reflect: true })\n size: 'sm' | 'md' | 'lg' = 'md';\n\n /**\n * Adds a shadow to elevate the component\n */\n @property({ type: Boolean })\n elevated = false;\n\n /**\n * Sets the `aria-label` on the icon\n * Use this to inform screenreaders of severity. Defaults to Norwegian.\n */\n @property({ type: String })\n iconlabel?: string;\n\n @state()\n private remainingTime = this.duration;\n\n @state()\n private notificationContent?: {\n title?: string;\n message: string;\n details?: string;\n };\n\n firstUpdated() {\n this.base.hidden = !this.open;\n }\n\n private restartAutoHide() {\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n if (this.open && this.duration < Infinity) {\n this.autoHideTimeout = window.setTimeout(\n () => this.hide(),\n this.duration\n );\n this.remainingTime = this.duration;\n this.remainingTimeInterval = window.setInterval(() => {\n this.remainingTime -= 100;\n }, 100);\n }\n }\n\n private pauseAutoHide() {\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n }\n\n private resumeAutoHide() {\n if (this.duration < Infinity) {\n this.autoHideTimeout = window.setTimeout(\n () => this.hide(),\n this.remainingTime\n );\n this.remainingTimeInterval = window.setInterval(() => {\n this.remainingTime -= 100;\n }, 100);\n }\n }\n\n @watch('open', { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n this.dispatchEvent(\n new Event('mid-show', { composed: true, bubbles: true })\n );\n\n if (this.duration < Infinity) {\n this.restartAutoHide();\n }\n\n await stopAnimations(this.base);\n this.base.hidden = false;\n const { keyframes, options } = getAnimation(this, 'alert.show');\n await animateTo(this.base, keyframes, options);\n\n this.dispatchEvent(\n new Event('mid-after-show', { composed: true, bubbles: true })\n );\n } else {\n // Hide\n this.dispatchEvent(\n new Event('mid-hide', { composed: true, bubbles: true })\n );\n\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n\n await stopAnimations(this.base);\n const { keyframes, options } = getAnimation(this, 'alert.hide');\n await animateTo(this.base, keyframes, options);\n this.base.hidden = true;\n\n this.dispatchEvent(\n new Event('mid-after-hide', { composed: true, bubbles: true })\n );\n }\n }\n\n @watch('duration')\n handleDurationChange() {\n this.restartAutoHide();\n }\n\n /**\n * Shows the alert.\n */\n async show() {\n if (this.open) {\n return undefined;\n }\n\n this.open = true;\n return waitForEvent(this, 'mid-after-show');\n }\n\n /**\n * Hides the alert\n */\n async hide() {\n if (!this.open) {\n return undefined;\n }\n\n this.open = false;\n return waitForEvent(this, 'mid-after-hide');\n }\n\n /**\n * Displays the alert as a toast notification. This will move the alert out of its position in the DOM and, when\n * dismissed, it will be removed from the DOM completely. By storing a reference to the alert, you can reuse it by\n * calling this method again. The returned promise will resolve after the alert is hidden.\n */\n async toast(\n content: MinidAlert['notificationContent'],\n duration?: number,\n severity?: MinidAlert['severity'],\n closable = true\n ) {\n return new Promise<void>((resolve) => {\n if (toastStack.parentElement === null) {\n document.body.append(toastStack);\n }\n\n if (content) {\n this.notificationContent = content;\n }\n\n if (severity) {\n this.severity = severity;\n }\n\n if (duration) {\n this.duration = duration;\n }\n\n this.closable = closable;\n this.elevated = true;\n\n // We wrap this in a timeout for `getBoundingClientRect` to get the height properly\n setTimeout(() => {\n toastStack.appendChild(this);\n\n animateTo(\n toastStack,\n [\n {\n transform: `translateY(${this.getBoundingClientRect().height}px)`,\n },\n { transform: 'translateY(0px)' },\n ],\n { duration: 250, easing: 'ease-out' }\n );\n }, 0);\n\n // Wait for the toast stack to render\n requestAnimationFrame(() => {\n // Force a reflow for the initial transition\n this.clientWidth;\n this.show();\n });\n\n this.addEventListener(\n 'mid-after-hide',\n () => {\n toastStack.removeChild(this);\n resolve();\n\n // Remove the toast stack from the DOM when there are no more alerts\n if (toastStack.querySelector('mid-alert') === null) {\n toastStack.remove();\n }\n },\n { once: true }\n );\n });\n }\n\n override render() {\n const danger = this.severity === 'danger';\n const warning = this.severity === 'warning';\n const info = this.severity === 'info';\n const success = this.severity === 'success';\n const sm = this.size === 'sm';\n const md = this.size === 'md';\n const lg = this.size === 'lg';\n const iconName: MidIconName =\n (danger && 'xmark-octagon-fill') ||\n (warning && 'exclamationmark-triangle-fill') ||\n (success && 'checkmark-circle-fill') ||\n 'information-square-fill';\n this.iconlabel ??=\n (danger && 'Feil') ||\n (warning && 'Advarsel') ||\n (success && 'Suksess') ||\n 'Informasjon';\n\n return html`\n <div\n part=\"base\"\n class=\"${classMap({\n 'text-body-sm': sm,\n 'text-body-md': md,\n 'text-body-lg': lg,\n 'bg-danger-surface-tinted': danger,\n 'bg-info-surface-tinted': info,\n 'bg-success-surface-tinted': success,\n 'bg-warning-surface-tinted': warning,\n 'border-danger': danger,\n 'border-info': info,\n 'border-success': success,\n 'border-warning': warning,\n 'text-danger': danger,\n 'text-info': info,\n 'text-success': success,\n 'text-warning': warning,\n 'shadow-md': this.elevated,\n })} grid grid-cols-[auto_1fr_auto] gap-2 rounded border p-6\"\n @mouseenter=${this.pauseAutoHide}\n @mouseleave=${this.resumeAutoHide}\n >\n <mid-icon\n class=\"${classMap({\n 'text-info-subtle': info,\n 'text-danger-subtle': danger,\n 'text-success-subtle': success,\n 'text-warning-subtle': warning,\n })} size-7\"\n name=\"${iconName}\"\n library=\"system\"\n alt=${ifDefined(this.iconlabel)}\n ></mid-icon>\n <div aria-live=\"polite\">\n <slot>\n ${!this.notificationContent?.title\n ? nothing\n : html`<h2 class=\"text-heading-xs\">\n ${this.notificationContent?.title}\n </h2>`}\n ${this.notificationContent?.message}\n ${!this.notificationContent?.details\n ? nothing\n : html`<div\n class=\"${classMap({\n 'border-danger': danger,\n 'border-info': info,\n 'border-success': success,\n 'border-warning': warning,\n 'bg-danger-surface-hover': danger,\n 'bg-info-surface-hover': info,\n 'bg-success-surface-hover': success,\n 'bg-warning-surface-hover': warning,\n })} text-body-sm mt-0.5 border-l-4 p-3\"\n >\n <pre class=\"break-all whitespace-pre-wrap\">\n${this.notificationContent?.details}</pre\n >\n </div>`}\n </slot>\n </div>\n ${this.closable\n ? html`\n <button\n class=\"${classMap({\n 'text-info-subtle': info,\n 'text-danger-subtle': danger,\n 'text-success-subtle': success,\n 'text-warning-subtle': warning,\n 'hover:bg-danger-surface-hover': danger,\n 'hover:bg-info-surface-hover': info,\n 'hover:bg-success-surface-hover': success,\n 'hover:bg-warning-surface-hover': warning,\n })} -my-4 -mr-4 flex self-center rounded p-4\"\n @click=\"${this.hide}\"\n aria-label=\"Dismiss alert\"\n >\n <mid-icon class=\"size-6\" name=\"xmark\"> </mid-icon>\n </button>\n `\n : nothing}\n </div>\n `;\n }\n}\n\nsetDefaultAnimation('alert.show', {\n keyframes: [\n { opacity: 0, transform: 'translateY(100%)' },\n { opacity: 1, transform: 'translateY(0px)' },\n ],\n options: { duration: 400, easing: 'ease-out' },\n});\n\nsetDefaultAnimation('alert.hide', {\n keyframes: [\n { opacity: 1, scale: 1 },\n { opacity: 0, scale: 0.8 },\n ],\n options: { duration: 250, easing: 'ease-in' },\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,aAAa,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;AAAA,EAC9D,WAAW;AACb,CAAC;AAiBM,IAAM,aAAN,cAAyB,OAAO,UAAU,EAAE;AAAA,EAA5C,cAAA;AAAA,UAAA,GAAA,SAAA;AAYL,SAAA,OAAO;AAMP,SAAA,WAAW;AAQX,SAAA,WAAW;AAMX,SAAA,WAAsD;AAMtD,SAAA,OAA2B;AAM3B,SAAA,WAAW;AAUX,SAAQ,gBAAgB,KAAK;AAAA,EAAA;AAAA,EAS7B,eAAe;AACb,SAAK,KAAK,SAAS,CAAC,KAAK;AAAA,EAC3B;AAAA,EAEQ,kBAAkB;AACxB,iBAAa,KAAK,eAAe;AACjC,kBAAc,KAAK,qBAAqB;AACxC,QAAI,KAAK,QAAQ,KAAK,WAAW,UAAU;AACzC,WAAK,kBAAkB,OAAO;AAAA,QAC5B,MAAM,KAAK,KAAA;AAAA,QACX,KAAK;AAAA,MAAA;AAEP,WAAK,gBAAgB,KAAK;AAC1B,WAAK,wBAAwB,OAAO,YAAY,MAAM;AACpD,aAAK,iBAAiB;AAAA,MACxB,GAAG,GAAG;AAAA,IACR;AAAA,EACF;AAAA,EAEQ,gBAAgB;AACtB,iBAAa,KAAK,eAAe;AAC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A,GAlDf,WAmDX,WAAA,aAAA,CAAA;AAGQ,gBAAA;AAAA,EADP,MAAA;AAAM,GArDI,WAsDH,WAAA,iBAAA,CAAA;AAGA,gBAAA;AAAA,EADP,MAAA;AAAM,GAxDI,WAyDH,WAAA,uBAAA,CAAA;AA2CF,gBAAA;AAAA,EADL,MAAM,QAAQ,EAAE,sBAAsB,MAAM;AAAA,GAnGlC,WAoGL,WAAA,oBAAA,CAAA;AAwCN,gBAAA;AAAA,EADC,MAAM,UAAU;AAAA,GA3IN,WA4IX,WAAA,wBAAA,CAAA;AA5IW,aAAN,gBAAA;AAAA,EADN,cAAc,WAAW;AAAA,GACb,UAAA;AAyVb,oBAAoB,cAAc;AAAA,EAChC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,WAAW,mBAAA;AAAA,IACzB,EAAE,SAAS,GAAG,WAAW,kBAAA;AAAA,EAAkB;AAAA,EAE7C,SAAS,EAAE,UAAU,KAAK,QAAQ,WAAA;AACpC,CAAC;AAED,oBAAoB,cAAc;AAAA,EAChC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,EAAA;AAAA,IACrB,EAAE,SAAS,GAAG,OAAO,IAAA;AAAA,EAAI;AAAA,EAE3B,SAAS,EAAE,UAAU,KAAK,QAAQ,UAAA;AACpC,CAAC;"}
|
|
1
|
+
{"version":3,"file":"alert.js","sources":["../../src/components/alert.component.ts"],"sourcesContent":["import { html, LitElement, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styled } from '../mixins/tailwind.mixin.ts';\nimport './icon/icon.component';\nimport { watch } from '../internal/watch';\nimport {\n getAnimation,\n setDefaultAnimation,\n} from '../utilities/animation-registry';\nimport { waitForEvent } from '../internal/event';\nimport { animateTo, stopAnimations } from '../internal/animate';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-alert': MinidAlert;\n }\n}\n\nconst toastStack = Object.assign(document.createElement('div'), {\n className: 'mid-toast-stack',\n});\n\n/**\n * Alerts need to have the `open` attribute to be displayed\n * @csspart base - Select the base of the alert\n *\n * @event mid-show - Emitted when the alert opens.\n * @event mid-after-show - Emitted after the alert opens and all animations are complete.\n * @event mid-hide - Emitted when the alert closes.\n * @event mid-after-hide - Emitted after the alert closes and all animations are complete.\n *\n * @slot -- The default slot for the content of the alert\n *\n * @animation alert.show - The animation to use when showing the alert.\n * @animation alert.hide - The animation to use when hiding the alert.\n */\n@customElement('mid-alert')\nexport class MinidAlert extends styled(LitElement) {\n private autoHideTimeout?: number;\n private remainingTimeInterval?: number;\n\n @query('[part~=\"base\"]')\n private base!: HTMLElement;\n\n /**\n * Indicates whether or not the alert is open. You can toggle this attribute to show and hide the alert, or you can\n * use the `show()` and `hide()` methods and this attribute will reflect the alert's open state.\n */\n @property({ type: Boolean, reflect: true })\n open = false;\n\n /**\n * Enables a close button that allows the user to dismiss the alert.\n */\n @property({ type: Boolean, reflect: true })\n closable = false;\n\n /**\n * The length of time, in milliseconds, the alert will show before closing itself. If the user interacts with\n * the alert before it closes (e.g. moves the mouse over it), the timer will restart. Defaults to `Infinity`, meaning\n * the alert will not close on its own.\n */\n @property({ type: Number })\n duration = Infinity;\n\n /**\n * Sets color and icon according to severity\n */\n @property({ reflect: true })\n severity: 'warning' | 'info' | 'danger' | 'success' = 'info';\n\n /**\n * Sets size of icon, padding and font-size.\n */\n @property({ reflect: true })\n size: 'sm' | 'md' | 'lg' = 'md';\n\n /**\n * Adds a shadow to elevate the component\n */\n @property({ type: Boolean })\n elevated = false;\n\n /**\n * Sets the `aria-live` attribute on the alert host element.\n * Prefer wrapping the alert in a `role=\"alert\"` or `aria-live` container instead.\n * Use `\"polite\"` for non-urgent updates and `\"assertive\"` for time-sensitive ones.\n * Defaults to `\"off\"`.\n */\n @property({ reflect: true })\n arialive: 'polite' | 'assertive' | 'off' = 'off';\n\n @state()\n private remainingTime = this.duration;\n\n @state()\n private notificationContent?: {\n title?: string;\n message: string;\n details?: string;\n };\n\n firstUpdated() {\n this.base.hidden = !this.open;\n }\n\n private restartAutoHide() {\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n if (this.open && this.duration < Infinity) {\n this.autoHideTimeout = window.setTimeout(\n () => this.hide(),\n this.duration\n );\n this.remainingTime = this.duration;\n this.remainingTimeInterval = window.setInterval(() => {\n this.remainingTime -= 100;\n }, 100);\n }\n }\n\n private pauseAutoHide() {\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n }\n\n private resumeAutoHide() {\n if (this.duration < Infinity) {\n this.autoHideTimeout = window.setTimeout(\n () => this.hide(),\n this.remainingTime\n );\n this.remainingTimeInterval = window.setInterval(() => {\n this.remainingTime -= 100;\n }, 100);\n }\n }\n\n @watch('open', { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n this.dispatchEvent(\n new Event('mid-show', { composed: true, bubbles: true })\n );\n\n if (this.duration < Infinity) {\n this.restartAutoHide();\n }\n\n await stopAnimations(this.base);\n this.base.hidden = false;\n const { keyframes, options } = getAnimation(this, 'alert.show');\n await animateTo(this.base, keyframes, options);\n\n this.dispatchEvent(\n new Event('mid-after-show', { composed: true, bubbles: true })\n );\n } else {\n // Hide\n this.dispatchEvent(\n new Event('mid-hide', { composed: true, bubbles: true })\n );\n\n clearTimeout(this.autoHideTimeout);\n clearInterval(this.remainingTimeInterval);\n\n await stopAnimations(this.base);\n const { keyframes, options } = getAnimation(this, 'alert.hide');\n await animateTo(this.base, keyframes, options);\n this.base.hidden = true;\n\n this.dispatchEvent(\n new Event('mid-after-hide', { composed: true, bubbles: true })\n );\n }\n }\n\n @watch('duration')\n handleDurationChange() {\n this.restartAutoHide();\n }\n\n /**\n * Shows the alert.\n */\n async show() {\n if (this.open) {\n return undefined;\n }\n\n this.open = true;\n return waitForEvent(this, 'mid-after-show');\n }\n\n /**\n * Hides the alert\n */\n async hide() {\n if (!this.open) {\n return undefined;\n }\n\n this.open = false;\n return waitForEvent(this, 'mid-after-hide');\n }\n\n /**\n * Displays the alert as a toast notification. This will move the alert out of its position in the DOM and, when\n * dismissed, it will be removed from the DOM completely. By storing a reference to the alert, you can reuse it by\n * calling this method again. The returned promise will resolve after the alert is hidden.\n */\n async toast(\n content: MinidAlert['notificationContent'],\n duration?: number,\n severity?: MinidAlert['severity'],\n closable = true\n ) {\n return new Promise<void>((resolve) => {\n if (toastStack.parentElement === null) {\n document.body.append(toastStack);\n }\n\n if (content) {\n this.notificationContent = content;\n }\n\n if (severity) {\n this.severity = severity;\n }\n\n if (duration) {\n this.duration = duration;\n }\n\n this.closable = closable;\n this.elevated = true;\n\n // We wrap this in a timeout for `getBoundingClientRect` to get the height properly\n setTimeout(() => {\n toastStack.appendChild(this);\n\n animateTo(\n toastStack,\n [\n {\n transform: `translateY(${this.getBoundingClientRect().height}px)`,\n },\n { transform: 'translateY(0px)' },\n ],\n { duration: 250, easing: 'ease-out' }\n );\n }, 0);\n\n // Wait for the toast stack to render\n requestAnimationFrame(() => {\n // Force a reflow for the initial transition\n this.clientWidth;\n this.show();\n });\n\n this.addEventListener(\n 'mid-after-hide',\n () => {\n toastStack.removeChild(this);\n resolve();\n\n // Remove the toast stack from the DOM when there are no more alerts\n if (toastStack.querySelector('mid-alert') === null) {\n toastStack.remove();\n }\n },\n { once: true }\n );\n });\n }\n\n override render() {\n const danger = this.severity === 'danger';\n const warning = this.severity === 'warning';\n const info = this.severity === 'info';\n const success = this.severity === 'success';\n\n return html`\n <div\n part=\"base\"\n class=\"ds-alert\"\n data-size=\"${this.size}\"\n data-color=\"${this.severity}\"\n @mouseenter=${this.pauseAutoHide}\n @mouseleave=${this.resumeAutoHide}\n >\n <div style=\"display: grid; grid-template-columns: 1fr ${this.closable ? 'auto' : ''};\">\n <div aria-live=\"${this.arialive}\">\n <slot>\n ${!this.notificationContent?.title\n ? nothing\n : html`<h2 class=\"text-heading-xs\">\n ${this.notificationContent?.title}\n </h2>`}\n ${this.notificationContent?.message}\n ${!this.notificationContent?.details\n ? nothing\n : html`<div\n class=\"${classMap({\n 'border-danger': danger,\n 'border-info': info,\n 'border-success': success,\n 'border-warning': warning,\n 'bg-danger-surface-hover': danger,\n 'bg-info-surface-hover': info,\n 'bg-success-surface-hover': success,\n 'bg-warning-surface-hover': warning,\n })} text-body-sm mt-0.5 border-l-4 p-3\"\n >\n <pre class=\"break-all whitespace-pre-wrap\">\n${this.notificationContent?.details}</pre\n >\n </div>`}\n </slot>\n </div>\n ${this.closable\n ? html`\n <button\n class=\"${classMap({\n 'text-info-subtle': info,\n 'text-danger-subtle': danger,\n 'text-success-subtle': success,\n 'text-warning-subtle': warning,\n 'hover:bg-danger-surface-hover': danger,\n 'hover:bg-info-surface-hover': info,\n 'hover:bg-success-surface-hover': success,\n 'hover:bg-warning-surface-hover': warning,\n })} flex rounded p-2\"\n style=\"align-self: start; justify-self: end;\"\n @click=\"${this.hide}\"\n aria-label=\"Dismiss alert\"\n >\n <mid-icon class=\"size-6\" name=\"xmark\"> </mid-icon>\n </button>\n `\n : nothing}\n </div>\n </div>\n `;\n }\n}\n\nsetDefaultAnimation('alert.show', {\n keyframes: [\n { opacity: 0, transform: 'translateY(100%)' },\n { opacity: 1, transform: 'translateY(0px)' },\n ],\n options: { duration: 400, easing: 'ease-out' },\n});\n\nsetDefaultAnimation('alert.hide', {\n keyframes: [\n { opacity: 1, scale: 1 },\n { opacity: 0, scale: 0.8 },\n ],\n options: { duration: 250, easing: 'ease-in' },\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAM,aAAa,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;AAAA,EAC9D,WAAW;AACb,CAAC;AAiBM,IAAM,aAAN,cAAyB,OAAO,UAAU,EAAE;AAAA,EAA5C,cAAA;AAAA,UAAA,GAAA,SAAA;AAYL,SAAA,OAAO;AAMP,SAAA,WAAW;AAQX,SAAA,WAAW;AAMX,SAAA,WAAsD;AAMtD,SAAA,OAA2B;AAM3B,SA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gBAAA;AAAA,EADP,MAAA;AAAM,GA1DI,WA2DH,WAAA,uBAAA,CAAA;AA2CF,gBAAA;AAAA,EADL,MAAM,QAAQ,EAAE,sBAAsB,MAAM;AAAA,GArGlC,WAsGL,WAAA,oBAAA,CAAA;AAwCN,gBAAA;AAAA,EADC,MAAM,UAAU;AAAA,GA7IN,WA8IX,WAAA,wBAAA,CAAA;AA9IW,aAAN,gBAAA;AAAA,EADN,cAAc,WAAW;AAAA,GACb,UAAA;AAuTb,oBAAoB,cAAc;AAAA,EAChC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,WAAW,mBAAA;AAAA,IACzB,EAAE,SAAS,GAAG,WAAW,kBAAA;AAAA,EAAkB;AAAA,EAE7C,SAAS,EAAE,UAAU,KAAK,QAAQ,WAAA;AACpC,CAAC;AAED,oBAAoB,cAAc;AAAA,EAChC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,EAAA;AAAA,IACrB,EAAE,SAAS,GAAG,OAAO,IAAA;AAAA,EAAI;AAAA,EAE3B,SAAS,EAAE,UAAU,KAAK,QAAQ,UAAA;AACpC,CAAC;"}
|
|
@@ -53,7 +53,7 @@ export declare class MinidButton extends MinidButton_base {
|
|
|
53
53
|
click(): void;
|
|
54
54
|
blur(): void;
|
|
55
55
|
focus(options?: FocusOptions): void;
|
|
56
|
-
render(): import('lit
|
|
56
|
+
render(): import('lit').TemplateResult;
|
|
57
57
|
}
|
|
58
58
|
export {};
|
|
59
59
|
//# sourceMappingURL=button.component.d.ts.map
|
|
@@ -12,7 +12,6 @@ declare const MinidCheckbox_base: import('../types/mixin-constructor.ts').Constr
|
|
|
12
12
|
* @event mid-change - Emitted when the checked state changes
|
|
13
13
|
*/
|
|
14
14
|
export declare class MinidCheckbox extends MinidCheckbox_base {
|
|
15
|
-
private readonly hasSlotController;
|
|
16
15
|
private input;
|
|
17
16
|
/**
|
|
18
17
|
* The name of the checkbox, submitted as a name/value pair with form data.
|
|
@@ -46,7 +45,7 @@ export declare class MinidCheckbox extends MinidCheckbox_base {
|
|
|
46
45
|
*/
|
|
47
46
|
blur(): void;
|
|
48
47
|
handleStateChange(): void;
|
|
49
|
-
render(): import('lit
|
|
48
|
+
render(): import('lit').TemplateResult<1>;
|
|
50
49
|
}
|
|
51
50
|
export {};
|
|
52
51
|
//# sourceMappingURL=checkbox.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.component.d.ts","sourceRoot":"","sources":["../../src/components/checkbox.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.component.d.ts","sourceRoot":"","sources":["../../src/components/checkbox.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAIvC,OAAO,0BAA0B,CAAC;AAMlC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,cAAc,EAAE,aAAa,CAAC;KAC/B;CACF;;AAED;;;;;GAKG;AAEH,qBACa,aAAc,SAAQ,kBAAoC;IAErE,OAAO,CAAC,KAAK,CAAoB;IAEjC;;OAEG;IAEH,IAAI,SAAM;IAEV;;OAEG;IAEH,KAAK,SAAQ;IAGb,OAAO,UAAS;IAGhB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,QAAQ,UAAS;IAGjB,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAGhB,QAAQ,UAAS;IAEjB,MAAM,KAAK,qBAAqB,qDAE/B;IAED,qBAAqB,IAAI,OAAO;IAIhC,IAAI,gBAAgB,qBAEnB;IAED,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,KAAK;IAIL;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY;IAI5B;;OAEG;IACH,IAAI;IAKJ,iBAAiB;IAKR,MAAM;CAiChB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LitElement, html } from "lit";
|
|
2
2
|
import { query, property, customElement } from "lit/decorators.js";
|
|
3
|
-
import { classMap } from "lit/directives/class-map.js";
|
|
4
3
|
import { live } from "lit/directives/live.js";
|
|
5
4
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
6
5
|
import "./icon/icon.js";
|
|
@@ -8,7 +7,6 @@ import { ifDefined } from "lit/directives/if-defined.js";
|
|
|
8
7
|
import { FormControlMixin } from "../mixins/form-control.mixin.js";
|
|
9
8
|
import { watch } from "../internal/watch.js";
|
|
10
9
|
import { requiredValidator } from "../mixins/validators.js";
|
|
11
|
-
import { HasSlotController } from "../internal/slot.js";
|
|
12
10
|
var __defProp = Object.defineProperty;
|
|
13
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
12
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -22,10 +20,6 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
22
20
|
let MinidCheckbox = class extends FormControlMixin(styled(LitElement)) {
|
|
23
21
|
constructor() {
|
|
24
22
|
super(...arguments);
|
|
25
|
-
this.hasSlotController = new HasSlotController(
|
|
26
|
-
this,
|
|
27
|
-
"description"
|
|
28
|
-
);
|
|
29
23
|
this.name = "";
|
|
30
24
|
this.value = "on";
|
|
31
25
|
this.checked = false;
|
|
@@ -79,59 +73,35 @@ let MinidCheckbox = class extends FormControlMixin(styled(LitElement)) {
|
|
|
79
73
|
this.setValue(this.value);
|
|
80
74
|
}
|
|
81
75
|
render() {
|
|
82
|
-
const hasDescriptionSlot = this.hasSlotController.test("description");
|
|
83
|
-
const hasDescription = this.description ? true : !!hasDescriptionSlot;
|
|
84
76
|
return html`
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"border-neutral": !this.readonly && !this.checked && !this.invalid,
|
|
98
|
-
"border-danger-base": !this.readonly && this.invalid,
|
|
99
|
-
"border-neutral-subtle": this.readonly,
|
|
100
|
-
"bg-neutral-surface-tinted": this.readonly
|
|
101
|
-
})} focus-within:focus-ring inline-flex size-6 shrink-0 items-center justify-center rounded-sm border-2"
|
|
102
|
-
>
|
|
103
|
-
<input
|
|
104
|
-
class="pointer-events-none appearance-none"
|
|
105
|
-
type="checkbox"
|
|
106
|
-
value=${ifDefined(this.value)}
|
|
107
|
-
.checked=${live(this.checked)}
|
|
108
|
-
?disabled=${this.disabled}
|
|
109
|
-
?checked=${this.checked}
|
|
110
|
-
?readonly=${this.readonly}
|
|
111
|
-
?required=${this.required}
|
|
112
|
-
@click=${this.handleClick}
|
|
113
|
-
@keydown=${this.handleKeydown}
|
|
77
|
+
<ds-field class="ds-field">
|
|
78
|
+
<input
|
|
79
|
+
class="ds-input"
|
|
80
|
+
type="checkbox"
|
|
81
|
+
value=${ifDefined(this.value)}
|
|
82
|
+
.checked=${live(this.checked)}
|
|
83
|
+
?disabled=${this.disabled}
|
|
84
|
+
?checked=${this.checked}
|
|
85
|
+
?readonly=${this.readonly}
|
|
86
|
+
?required=${this.required}
|
|
87
|
+
@click=${this.handleClick}
|
|
88
|
+
@keydown=${this.handleKeydown}
|
|
114
89
|
/>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
name="checkmark"
|
|
120
|
-
></mid-icon>` : ""}
|
|
121
|
-
</span>
|
|
122
|
-
<div part="label">
|
|
90
|
+
<label
|
|
91
|
+
class="ds-label"
|
|
92
|
+
part="label"
|
|
93
|
+
>
|
|
123
94
|
<slot></slot>
|
|
95
|
+
</label>
|
|
96
|
+
<div data-field="description">
|
|
97
|
+
<slot
|
|
98
|
+
name="description"
|
|
99
|
+
part="description"
|
|
100
|
+
>
|
|
101
|
+
${this.description}
|
|
102
|
+
</slot>
|
|
124
103
|
</div>
|
|
125
|
-
</
|
|
126
|
-
<slot
|
|
127
|
-
name="description"
|
|
128
|
-
part="description"
|
|
129
|
-
name="description"
|
|
130
|
-
class="text-neutral-subtle mt-2 block"
|
|
131
|
-
aria-hidden=${hasDescription ? "false" : "true"}
|
|
132
|
-
>
|
|
133
|
-
${this.description}
|
|
134
|
-
</slot>
|
|
104
|
+
</ds-field>
|
|
135
105
|
`;
|
|
136
106
|
}
|
|
137
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","sources":["../../src/components/checkbox.component.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport {
|
|
1
|
+
{"version":3,"file":"checkbox.js","sources":["../../src/components/checkbox.component.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\nimport { styled } from '../mixins/tailwind.mixin';\nimport './icon/icon.component.ts';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { FormControlMixin } from '../mixins/form-control.mixin.ts';\nimport { watch } from '../internal/watch.ts';\nimport { requiredValidator } from '../mixins/validators.ts';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-checkbox': MinidCheckbox;\n }\n}\n\n/**\n * @slot -- The default slot for the label text of the checkbox\n * @slot description - The slot for the description text of the checkbox\n *\n * @event mid-change - Emitted when the checked state changes\n */\n\n@customElement('mid-checkbox')\nexport class MinidCheckbox extends FormControlMixin(styled(LitElement)) {\n @query('input[type=\"checkbox\"]')\n private input!: HTMLInputElement;\n\n /**\n * The name of the checkbox, submitted as a name/value pair with form data.\n */\n @property()\n name = '';\n\n /**\n * The current value of the checkbox, submitted as a name/value pair with form data.\n */\n @property()\n value = 'on';\n\n @property({ type: Boolean })\n checked = false;\n\n @property()\n description?: string;\n\n @property({ type: Boolean })\n disabled = false;\n\n @property({ type: Boolean })\n readonly = false;\n\n @property({ type: Boolean })\n invalid = false;\n\n @property({ type: Boolean, reflect: true })\n required = false;\n\n static get formControlValidators() {\n return [requiredValidator];\n }\n\n shouldFormValueUpdate(): boolean {\n return this.checked;\n }\n\n get validationTarget() {\n return this.input;\n }\n\n private handleKeydown(event: KeyboardEvent) {\n const hasModifier =\n event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n\n // Pressing enter when focused on an input should submit the form like a native input, but we wait a tick before\n // submitting to allow users to cancel the keydown event if they need to\n if (event.key === 'Enter' && !hasModifier) {\n setTimeout(() => {\n //\n // When using an Input Method Editor (IME), pressing enter will cause the form to submit unexpectedly. One way\n // to check for this is to look at event.isComposing, which will be true when the IME is open.\n if (!event.defaultPrevented && !event.isComposing) {\n this.form.requestSubmit();\n }\n });\n }\n }\n\n private handleClick() {\n this.checked = !this.checked;\n // this.indeterminate = false;\n this.dispatchEvent(new Event('mid-change'));\n }\n\n /**\n * Simulates a click on the checkbox.\n */\n click() {\n this.input.click();\n }\n\n /**\n * Sets focus on the checkbox.\n */\n focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /**\n * Removes focus from the checkbox.\n */\n blur() {\n this.input.blur();\n }\n\n @watch(['checked', 'value'])\n handleStateChange() {\n // this.input.indeterminate = this.indeterminate; // force a sync update\n this.setValue(this.value);\n }\n\n override render() {\n\n return html`\n <ds-field class=\"ds-field\">\n <input\n class=\"ds-input\"\n type=\"checkbox\"\n value=${ifDefined(this.value)}\n .checked=${live(this.checked)}\n ?disabled=${this.disabled}\n ?checked=${this.checked}\n ?readonly=${this.readonly}\n ?required=${this.required}\n @click=${this.handleClick}\n @keydown=${this.handleKeydown}\n />\n <label\n class=\"ds-label\"\n part=\"label\"\n >\n <slot></slot>\n </label>\n <div data-field=\"description\">\n <slot\n name=\"description\"\n part=\"description\"\n >\n ${this.description}\n </slot>\n </div>\n </ds-field>\n `;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAwBO,IAAM,gBAAN,cAA4B,iBAAiB,OAAO,UAAU,CAAC,EAAE;AAAA,EAAj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KAAK,QAAQ;AAAA,mBAChB,KAAK,WAAW;AAAA,qBACd,KAAK,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAazB,KAAK,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAK5B;AACF;AAhIU,gBAAA;AAAA,EADP,MAAM,wBAAwB;AAAA,GADpB,cAEH,WAAA,SAAA,CAAA;AAMR,gBAAA;AAAA,EADC,SAAA;AAAS,GAPC,cAQX,WAAA,QAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAA;AAAS,GAbC,cAcX,WAAA,SAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GAhBhB,cAiBX,WAAA,WAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAA;AAAS,GAnBC,cAoBX,WAAA,eAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GAtBhB,cAuBX,WAAA,YAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GAzBhB,cA0BX,WAAA,YAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GA5BhB,cA6BX,WAAA,WAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,SAAS,SAAS,MAAM;AAAA,GA/B/B,cAgCX,WAAA,YAAA,CAAA;AA4DA,gBAAA;AAAA,EADC,MAAM,CAAC,WAAW,OAAO,CAAC;AAAA,GA3FhB,cA4FX,WAAA,qBAAA,CAAA;AA5FW,gBAAN,gBAAA;AAAA,EADN,cAAc,cAAc;AAAA,GAChB,aAAA;"}
|
|
@@ -49,7 +49,7 @@ export declare class MinidCodeInputOld extends MinidCodeInputOld_base {
|
|
|
49
49
|
updated(_changedProperties: PropertyValues): void;
|
|
50
50
|
focus(options?: FocusOptions): void;
|
|
51
51
|
setCustomValidity(error: string): void;
|
|
52
|
-
render(): import('lit
|
|
52
|
+
render(): import('lit').TemplateResult<1>;
|
|
53
53
|
}
|
|
54
54
|
export {};
|
|
55
55
|
//# sourceMappingURL=code-input-old.component.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { property, state, customElement } from "lit/decorators.js";
|
|
|
3
3
|
import { createRef, ref } from "lit/directives/ref.js";
|
|
4
4
|
import { classMap } from "lit/directives/class-map.js";
|
|
5
5
|
import { live } from "lit/directives/live.js";
|
|
6
|
-
import {
|
|
6
|
+
import { webOtpApiClose, webOtpApiInit } from "../utilities/web-otp-api.js";
|
|
7
7
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
8
8
|
import { ConstraintsValidationMixin } from "../mixins/form-controller.mixin.js";
|
|
9
9
|
import "./icon/icon.js";
|
|
@@ -82,7 +82,7 @@ export declare class MinidCodeInput extends MinidCodeInput_base {
|
|
|
82
82
|
resetFormControl(): void;
|
|
83
83
|
focus(options?: FocusOptions): void;
|
|
84
84
|
handleLengthChange(): void;
|
|
85
|
-
render(): import('lit
|
|
85
|
+
render(): import('lit').TemplateResult<1>;
|
|
86
86
|
}
|
|
87
87
|
export {};
|
|
88
88
|
//# sourceMappingURL=code-input.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-input.component.d.ts","sourceRoot":"","sources":["../../src/components/code-input.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAS5D,OAAO,0BAA0B,CAAC;AASlC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,cAAc,CAAC;KAClC;CACF;;
|
|
1
|
+
{"version":3,"file":"code-input.component.d.ts","sourceRoot":"","sources":["../../src/components/code-input.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CA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