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

Add a title slot to the Card component #1638

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion packages/nimble-components/src/card/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
borderColor,
borderWidth,
sectionBackgroundColor,
standardPadding
standardPadding,
titleFont
} from '../theme-provider/design-tokens';

export const styles = css`
Expand All @@ -21,4 +22,12 @@ export const styles = css`
color: ${bodyFontColor};
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
background-color: ${sectionBackgroundColor};
}

::slotted([slot='title']) {
font: ${titleFont};
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
}

section {
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
display: contents;
}
`;
7 changes: 6 additions & 1 deletion packages/nimble-components/src/card/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { html } from '@microsoft/fast-element';
import type { Card } from '.';

export const template = html<Card>`<slot></slot>`;
export const template = html<Card>`
<section aria-labelledby="titleSlot">
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
<slot name="title" id="titleSlot"></slot>
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
<slot></slot>
</section>
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
`;
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default metadata;

const component = (): ViewTemplate => html`
<${cardTag}>
<span slot="title">Title</span>
<${numberFieldTag}>Numeric field 1</${numberFieldTag}>
<${numberFieldTag}>Numeric field 2</${numberFieldTag}>
<${selectTag}>
Expand Down
20 changes: 17 additions & 3 deletions packages/nimble-components/src/card/tests/card.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import { numberFieldTag } from '../../number-field';
import { selectTag } from '../../select';
import { cardTag } from '..';

interface CardArgs {
title: string;
}

const overviewText = `The \`nimble-card\` is a container that is designed to contain arbitrary content that is specified by a client
application. The \`nimble-card\` is intended for grouping related content.`;

const metadata: Meta = {
const metadata: Meta<CardArgs> = {
title: 'Incubating/Card',
tags: ['autodocs'],
parameters: {
Expand All @@ -29,6 +33,7 @@ const metadata: Meta = {
statusLink: 'https://github.com/ni/nimble/issues/296'
})}
<${cardTag}>
<span slot="title">${x => x.title}</span>
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
<${numberFieldTag}>Numeric field 1</${numberFieldTag}>
<${numberFieldTag}>Numeric field 2</${numberFieldTag}>
<${selectTag}>
Expand All @@ -37,9 +42,18 @@ const metadata: Meta = {
<${listOptionTag} value="3">Option 3</${listOptionTag}>
</${selectTag}>
</${cardTag}>
`)
`),
argTypes: {
title: {
description:
'Text displayed as a title inside the card. Cards should **always include a title**. The title is used to provide an accessible name to assistive technologies.<br><br>Provide the title in an `inline` element such as `<span>` that is targeted to the `title` slot.'
kjohn1922 marked this conversation as resolved.
Show resolved Hide resolved
}
},
args: {
title: 'Title text'
}
};

export default metadata;

export const card: StoryObj = {};
export const card: StoryObj<CardArgs> = {};
Loading