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

[POC] Extend/inherit component #798

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/storybook/stories/va-card.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const Template = ({
</va-card>
);

const CardExtendedTemplate = ({
'show-shadow': showShadow,
}) => (
<va-card-extended
show-shadow={showShadow}
>
<p>Example card content</p>
</va-card-extended>
);

export const Default = Template.bind(null);
Default.args = {
...defaultArgs,
Expand All @@ -40,3 +50,9 @@ withDropShadow.args = {
...defaultArgs,
'show-shadow': true,
};

export const CardExtended = CardExtendedTemplate.bind(null);
CardExtended.args = {
...defaultArgs,
'show-shadow': true,
};
3 changes: 2 additions & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"aria-hidden": "^1.1.3",
"body-scroll-lock": "^4.0.0-beta.0",
"classnames": "^2.3.1",
"intersection-observer": "^0.12.0"
"intersection-observer": "^0.12.0",
"typescript-mix": "^3.1.3"
},
"license": "MIT",
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions packages/web-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ export namespace Components {
*/
"showShadow"?: boolean;
}
interface VaCardExtended {
}
interface VaCheckbox {
/**
* Description of the option displayed below the checkbox label. Available when uswds is true.
Expand Down Expand Up @@ -1399,6 +1401,12 @@ declare global {
prototype: HTMLVaCardElement;
new (): HTMLVaCardElement;
};
interface HTMLVaCardExtendedElement extends Components.VaCardExtended, HTMLStencilElement {
}
var HTMLVaCardExtendedElement: {
prototype: HTMLVaCardExtendedElement;
new (): HTMLVaCardExtendedElement;
};
interface HTMLVaCheckboxElement extends Components.VaCheckbox, HTMLStencilElement {
}
var HTMLVaCheckboxElement: {
Expand Down Expand Up @@ -1609,6 +1617,7 @@ declare global {
"va-button": HTMLVaButtonElement;
"va-button-pair": HTMLVaButtonPairElement;
"va-card": HTMLVaCardElement;
"va-card-extended": HTMLVaCardExtendedElement;
"va-checkbox": HTMLVaCheckboxElement;
"va-checkbox-group": HTMLVaCheckboxGroupElement;
"va-date": HTMLVaDateElement;
Expand Down Expand Up @@ -1947,6 +1956,8 @@ declare namespace LocalJSX {
*/
"showShadow"?: boolean;
}
interface VaCardExtended {
}
interface VaCheckbox {
/**
* Description of the option displayed below the checkbox label. Available when uswds is true.
Expand Down Expand Up @@ -3066,6 +3077,7 @@ declare namespace LocalJSX {
"va-button": VaButton;
"va-button-pair": VaButtonPair;
"va-card": VaCard;
"va-card-extended": VaCardExtended;
"va-checkbox": VaCheckbox;
"va-checkbox-group": VaCheckboxGroup;
"va-date": VaDate;
Expand Down Expand Up @@ -3116,6 +3128,7 @@ declare module "@stencil/core" {
"va-button": LocalJSX.VaButton & JSXBase.HTMLAttributes<HTMLVaButtonElement>;
"va-button-pair": LocalJSX.VaButtonPair & JSXBase.HTMLAttributes<HTMLVaButtonPairElement>;
"va-card": LocalJSX.VaCard & JSXBase.HTMLAttributes<HTMLVaCardElement>;
"va-card-extended": LocalJSX.VaCardExtended & JSXBase.HTMLAttributes<HTMLVaCardExtendedElement>;
"va-checkbox": LocalJSX.VaCheckbox & JSXBase.HTMLAttributes<HTMLVaCheckboxElement>;
"va-checkbox-group": LocalJSX.VaCheckboxGroup & JSXBase.HTMLAttributes<HTMLVaCheckboxGroupElement>;
"va-date": LocalJSX.VaDate & JSXBase.HTMLAttributes<HTMLVaDateElement>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '../va-card/va-card.scss';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, Host, h } from '@stencil/core';
import { use } from 'typescript-mix';
import classnames from 'classnames';

import { VaCard } from '../va-card/va-card';

export interface VaCardExtended extends VaCard {}

@Component({
tag: 'va-card-extended',
styleUrl: 'va-card-extended.scss',
shadow: true,
})
export class VaCardExtended {

@use(VaCard) this: VaCard;

render() {
const classes = classnames('va-card', {'show-shadow': this.showShadow});
return (
<Host class={classes}>
<slot></slot>
</Host>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ICardComponent {
showShadow?: boolean;
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,7 @@ __metadata:
puppeteer: ^10.0.0
react-dom: ^16.7.0
typescript: ^4.3.5
typescript-mix: ^3.1.3
peerDependencies:
"@department-of-veterans-affairs/formation": ^7.0.8
i18next: "*"
Expand Down Expand Up @@ -19491,6 +19492,13 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"typescript-mix@npm:^3.1.3":
version: 3.1.3
resolution: "typescript-mix@npm:3.1.3"
checksum: 5cd0791489462aff3f4602a42dbc2d390f3b91289eac952912e2d05adce988d20413eddbf9bb76cb37dbb56fdd19c1b6e9f15e095985539889ffdeb96932e082
languageName: node
linkType: hard

typescript@^4.3.5:
version: 4.5.5
resolution: "typescript@npm:4.5.5"
Expand Down