Skip to content

Commit

Permalink
BREAKING CHANGE(web): Toast JS plugin linkProps changed to underlined
Browse files Browse the repository at this point in the history
- `isUnderlined` changed to `underlined` in `Toast` JS plugin to better
reflect changes in react and twig `Link` component

- solves #DS-1509
  • Loading branch information
pavelklibani committed Oct 16, 2024
1 parent 83df04c commit 84d30b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/web/src/js/Toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CLASS_NAME_TRANSITIONING,
CLASS_NAME_VISIBLE,
DEFAULT_TOAST_AUTO_CLOSE_INTERVAL,
CLASS_NAME_LINK_NOT_UNDERLINED,
} from './constants';
import { EventHandler, SelectorEngine } from './dom';
import { enableDismissTrigger, enableToggleTrigger, executeAfterTransition, SpiritConfig } from './utils';
Expand All @@ -35,6 +36,12 @@ const COLOR_ICON_MAP = {
warning: 'warning',
};

const UNDERLINE_MAP = {
hover: 'hover',
always: 'always',
never: 'never',
};

const SELECTOR_QUEUE_ELEMENT = `[${ATTRIBUTE_DATA_ELEMENT}="toast-queue"]`;
const SELECTOR_TEMPLATE_ELEMENT = `[${ATTRIBUTE_DATA_SNIPPET}="item"]`;
const SELECTOR_ITEM_ELEMENT = `[${ATTRIBUTE_DATA_POPULATE_FIELD}="item"]`;
Expand All @@ -52,6 +59,7 @@ export const PROPERTY_NAME_SLOWEST_TRANSITION = {
const PROPERTY_NAME_FALLBACK_TRANSITION = 'opacity';

type Color = keyof typeof COLOR_ICON_MAP;
type Underlined = keyof typeof UNDERLINE_MAP;

type Config = {
autoCloseInterval: number;
Expand All @@ -66,7 +74,7 @@ type Config = {
elementType: string;
href: string;
isDisabled: boolean;
isUnderlined: boolean;
underlined: Underlined;
target: '_blank' | '_self' | '_parent' | '_top';
};
hasIcon: boolean;
Expand Down Expand Up @@ -195,12 +203,15 @@ class Toast extends BaseComponent {
if (linkContent) {
const linkElementWithType = document.createElement(linkProps.elementType || 'a');
linkElement.replaceWith(linkElementWithType);
const isUnderlined = linkProps.isUnderlined != null ? linkProps.isUnderlined : true;
const { underlined = UNDERLINE_MAP.always } = linkProps;

linkElementWithType.classList.add('ToastBar__link');
if (isUnderlined) {
if (underlined === UNDERLINE_MAP.always) {
linkElementWithType.classList.add(CLASS_NAME_LINK_UNDERLINED);
}
if (underlined === UNDERLINE_MAP.never) {
linkElementWithType.classList.add(CLASS_NAME_LINK_NOT_UNDERLINED);
}
if (linkProps.isDisabled) {
linkElementWithType.classList.add(CLASS_NAME_LINK_DISABLED);
}
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/js/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CLASS_NAME_OPEN = 'is-open';
export const CLASS_NAME_TRANSITIONING = 'is-transitioning';
export const CLASS_NAME_VISIBLE = 'is-visible';
export const CLASS_NAME_LINK_UNDERLINED = 'link-underlined';
export const CLASS_NAME_LINK_NOT_UNDERLINED = 'link-not-underlined';
export const CLASS_NAME_LINK_DISABLED = 'link-disabled';

export const DEFAULT_TOAST_AUTO_CLOSE_INTERVAL = 3000; // milliseconds
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/scss/components/Toast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const toast = new Toast(null, {
linkProps: {
href: 'https://example.com', // Link URL
target: '_blank', // Optional link target attribute
isUnderlined: false, // Optional link underlining, default: true
underlined: false, // Optional link underlining, Optional link underlining, one of ['always' (default), 'hover', 'never']
isDisabled: false, // Optional link disabling, default: false
elementType: 'a', // Optional link element type, default: 'a'
},
Expand Down

0 comments on commit 84d30b3

Please sign in to comment.