Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(components): update crypto to nanoid #4369

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-grapes-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': patch
---

Reduced the length of random IDs generated in the components; they are now generated using the [nanoid library](https://github.com/ai/nanoid) instead of the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Element, h, Host, Listen, Method, Prop, State, Watch } from
import { version } from '@root/package.json';
import { HEADING_LEVELS, HeadingLevel } from '@/types';
import { checkEmptyOrOneOf } from '@/utils';
import { nanoid } from 'nanoid';

/**
* @part button - The pseudo-element, used to override styles on the components internal header `button` element.
Expand Down Expand Up @@ -46,7 +47,7 @@ export class PostAccordionItem {
}

componentWillLoad() {
this.id = this.host.id || `a${crypto.randomUUID()}`;
this.id = this.host.id || `p${nanoid(6)}`;
}

componentDidLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { version } from '@root/package.json';
import { fadeOut } from '@/animations';
import { checkEmptyOrOneOf, checkEmptyOrPattern, checkNonEmpty, checkType } from '@/utils';
import { BANNER_TYPES, BannerType } from './banner-types';
import { nanoid } from 'nanoid';

/**
* @slot heading - Slot for placing custom content within the banner's heading.
Expand All @@ -29,7 +30,7 @@ import { BANNER_TYPES, BannerType } from './banner-types';
export class PostBanner {
@Element() host: HTMLPostBannerElement;

@State() bannerId = crypto.randomUUID();
@State() bannerId = `p${nanoid(6)}`;
alizedebray marked this conversation as resolved.
Show resolved Hide resolved
@State() classes: string;
@State() hasActions: boolean;
@State() hasHeading: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Element, Prop, Host, State, h } from '@stencil/core';
import { version } from '@root/package.json';
import { nanoid } from 'nanoid';

/**
* @slot default - Slot for placing the list title.
Expand Down Expand Up @@ -35,7 +36,7 @@ export class PostList {
/**
* Get the id set on the host element or use a random id by default
*/
this.titleId = `title-${this.host.id || crypto.randomUUID()}`;
this.titleId = `title-${this.host.id || nanoid(6)}`;
}

componentDidLoad() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Element, h, Host, Prop, State, Watch } from '@stencil/core';
import { version } from '@root/package.json';
import { checkNonEmpty } from '@/utils';
import { nanoid } from 'nanoid';

/**
* @slot default - Slot for the content of the tab header.
Expand All @@ -27,7 +28,7 @@ export class PostTabHeader {
}

componentWillLoad() {
this.tabId = `tab-${this.host.id || crypto.randomUUID()}`;
this.tabId = `tab-${this.host.id || nanoid(6)}`;
}

render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { version } from '@root/package.json';
import { nanoid } from 'nanoid';

/**
* @slot default - Slot for placing the content of the tab panel.
Expand All @@ -22,7 +23,7 @@ export class PostTabPanel {

componentWillLoad() {
// get the id set on the host element or use a random id by default
this.panelId = `panel-${this.host.id || crypto.randomUUID()}`;
this.panelId = `panel-${this.host.id || nanoid(6)}`;
}

render() {
Expand Down
Loading