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

HDS-2717: Toast - Convert to TypeScript #2023

Merged
merged 5 commits into from
Apr 9, 2024
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/soft-buttons-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashicorp/design-system-components": minor
---

`Toast` - Converted component to TypeScript
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"./components/hds/text/index.js": "./dist/_app_/components/hds/text/index.js",
"./components/hds/text/types.js": "./dist/_app_/components/hds/text/types.js",
"./components/hds/toast/index.js": "./dist/_app_/components/hds/toast/index.js",
"./components/hds/toast/types.js": "./dist/_app_/components/hds/toast/types.js",
"./components/hds/tooltip-button/index.js": "./dist/_app_/components/hds/tooltip-button/index.js",
"./components/hds/yield/index.js": "./dist/_app_/components/hds/yield/index.js",
"./components/hds/yield/types.js": "./dist/_app_/components/hds/yield/types.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/components/hds/alert/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface HdsAlertSignature {
type: HdsAlertTypes;
color?: HdsAlertColors;
icon?: string | false;
onDismiss?: () => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onDismiss?: (event: MouseEvent, ...args: any[]) => void;
};
Blocks: {
default: [
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/components/hds/toast/index.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/components/hds/toast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import TemplateOnlyComponent from '@ember/component/template-only';
import type { HdsToastSignature } from './types.ts';

const HdsToastComponent = TemplateOnlyComponent<HdsToastSignature>();

export default HdsToastComponent;
5 changes: 5 additions & 0 deletions packages/components/src/components/hds/toast/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HdsAlertSignature } from '../alert/types.ts';

export interface HdsToastSignature extends Omit<HdsAlertSignature, 'Args'> {
Args: Omit<HdsAlertSignature['Args'], 'type'>;
}
Comment on lines +3 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good example of how TypeScript could help us spot issues. While this interface is accurate (the Toast component doesn't expose a @type argument) we didn't document it as such in the component API. I will raise a follow-up PR to correct that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I initially had it implementing the Alert interface and realized afterwards that inline is hardcoded in Toast. πŸ‘

8 changes: 7 additions & 1 deletion packages/components/src/template-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import type HdsAlertIndexComponent from './components/hds/alert';
import type HdsAlertDescriptionComponent from './components/hds/alert/description';
import type HdsAlertTitleComponent from './components/hds/alert/title';
import type HdsButtonIndexComponent from './components/hds/button';
import type HdsCardContainerComponent from './components/hds/card/container.ts';
import type HdsDismissButtonIndexComponent from './components/hds/dismiss-button';
import type HdsInteractiveIndexComponent from './components/hds/interactive';
import type HdsLinkInlineComponent from './components/hds/link/inline';
import type HdsLinkStandaloneComponent from './components/hds/link/standalone';
import type HdsTextIndexComponent from './components/hds/text';
import type HdsTextBodyComponent from './components/hds/text/body';
import type HdsTextDisplayComponent from './components/hds/text/display';
import type HdsToastComponent from './components/hds/toast';
import type HdsTextCodeComponent from './components/hds/text/code';
import type HdsYieldComponent from './components/hds/yield';
import type HdsLinkToModelsHelper from './helpers/hds-link-to-models';
import type HdsLinkToQueryHelper from './helpers/hds-link-to-query';
import type HdsCardContainerComponent from './components/hds/card/container.ts';

export default interface HdsComponentsRegistry {
// Alert
Expand Down Expand Up @@ -81,6 +82,11 @@ export default interface HdsComponentsRegistry {
'hds/text/code': typeof HdsTextCodeComponent;
HdsTextCode: typeof HdsTextCodeComponent;

// Toast
'Hds::Toast': typeof HdsToastComponent;
'hds/toast': typeof HdsToastComponent;
HdsToast: typeof HdsToastComponent;

// Yield
'Hds::Yield': typeof HdsYieldComponent;
'hds/yield': typeof HdsYieldComponent;
Expand Down
3 changes: 3 additions & 0 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"@hashicorp/design-system-components/*": [
"src/*"
],
"@ember/component/template-only": [
"../../../node_modules/ember-source/types/stable/@ember/component/template-only"
],
"*": [
"types/*"
]
Expand Down