Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinLBradley committed May 16, 2024
1 parent 08f9b2a commit daede28
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
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
33 changes: 25 additions & 8 deletions packages/components/src/components/hds/copy/snippet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import type { HdsCopySnippetColors } from './types';

export const DEFAULT_COLOR = 'primary';
export const COLORS = ['primary', 'secondary'];
Expand All @@ -15,9 +16,23 @@ export const SUCCESS_ICON = 'clipboard-checked';
export const ERROR_ICON = 'clipboard-x';
export const DEFAULT_STATUS = 'idle';

export default class HdsCopySnippetIndexComponent extends Component {
interface HdsCopySnippetSignature {
Args: {
color?: HdsCopySnippetColors;
isFullWidth?: boolean;
isTruncated?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onError?: (...args: any[]) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSuccess?: (...args: any[]) => void;
textToCopy: string;
};
Element: HTMLButtonElement;
}

export default class HdsCopySnippetComponent extends Component<HdsCopySnippetSignature> {
@tracked status = DEFAULT_STATUS;
@tracked timer;
@tracked timer: ReturnType<typeof setTimeout> | undefined;

/**
* @param icon
Expand All @@ -42,7 +57,7 @@ export default class HdsCopySnippetIndexComponent extends Component {
* @description Determines the color of button to be used; acceptable values are `primary` and `secondary`
*/
get color() {
let { color = DEFAULT_COLOR } = this.args;
const { color = DEFAULT_COLOR } = this.args;

assert(
`@color for "Hds::Copy::Snippet" must be one of the following: ${COLORS.join(
Expand Down Expand Up @@ -80,7 +95,7 @@ export default class HdsCopySnippetIndexComponent extends Component {
* @return {string} The "class" attribute to apply to the component.
*/
get classNames() {
let classes = ['hds-copy-snippet'];
const classes = ['hds-copy-snippet'];

// add a class based on the @color argument
classes.push(`hds-copy-snippet--color-${this.color}`);
Expand All @@ -102,23 +117,25 @@ export default class HdsCopySnippetIndexComponent extends Component {
}

@action
onSuccess(args) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSuccess(args: any) {
this.status = 'success';
this.resetStatusDelayed();

let { onSuccess } = this.args;
const { onSuccess } = this.args;

if (typeof onSuccess === 'function') {
onSuccess(args);
}
}

@action
onError(args) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onError(args: any) {
this.status = 'error';
this.resetStatusDelayed();

let { onError } = this.args;
const { onError } = this.args;

if (typeof onError === 'function') {
onError(args);
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/components/hds/copy/snippet/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

export enum HdsCopySnippetColorValues {
Primary = 'primary',
Secondary = 'secondary',
}
export type HdsCopySnippetColors = `${HdsCopySnippetColorValues}`;
6 changes: 6 additions & 0 deletions packages/components/src/template-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type HdsBadgeCountIndexComponent from './components/hds/badge-count';
import type HdsButtonIndexComponent from './components/hds/button';
import type HdsCardContainerComponent from './components/hds/card/container.ts';
import type HdsCopyButtonComponent from './components/hds/copy/button/index';
import type HdsCopySnippetComponent from './components/hds/copy/snippet';
import type HdsDisclosurePrimitiveComponent from './components/hds/disclosure-primitive';
import type HdsDismissButtonIndexComponent from './components/hds/dismiss-button';
import type HdsIconTileIndexComponent from './components/hds/icon-tile';
Expand Down Expand Up @@ -69,6 +70,11 @@ export default interface HdsComponentsRegistry {
'hds/copy/button': typeof HdsCopyButtonComponent;
HdsCopyButton: typeof HdsCopyButtonComponent;

// Copy Snippet
'Hds::Copy::Snippet': typeof HdsCopySnippetComponent;
'hds/copy/snippet': typeof HdsCopySnippetComponent;
HdsCopySnippet: typeof HdsCopySnippetComponent;

// Disclosure Primitive
'Hds::DisclosurePrimitive': typeof HdsDisclosurePrimitiveComponent;
'hds/disclosure-primitive': typeof HdsDisclosurePrimitiveComponent;
Expand Down

0 comments on commit daede28

Please sign in to comment.