Skip to content

Commit

Permalink
feat: label css
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWebb committed Feb 9, 2024
1 parent 1b3104b commit 38f2ec1
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
9 changes: 9 additions & 0 deletions components/control/Label/Label.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
label,
legend {
align-items: center;
color: var(--diamond-label-color);
display: flex;
font-size: var(--diamond-label-font-size);
font-weight: var(--diamond-label-font-weight);
min-height: var(--diamond-label-height);
}
55 changes: 55 additions & 0 deletions components/control/Label/Label.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import '../Input/Input';

const description = `
Diamond provides some customisable base styles applied to the \`<label>\` and \`<legend>\` elements.
`;

export default {
component: 'label',
parameters: {
docs: {
description: {
component: description,
},
},
},
};

export const Label: StoryObj = {
render: () => html`
<label for="input-with-label">Label</label>
<diamond-input>
<input id="input-with-label" />
</diamond-input>
`,
};

export const Legend: StoryObj = {
render: () => html`
<fieldset>
<legend>Legend</legend>
<diamond-input>
<input />
</diamond-input>
</fieldset>
`,
};

export const ScreenReaderOnly: StoryObj = {
render: () => html`
<p>The invisible label content below is read by screen readers</p>
<label for="input-with-label" class="diamond-sr-only">Label</label>
`,
};

ScreenReaderOnly.parameters = {
docs: {
description: {
story:
'Occasionally, a label is only helpful when a screen reader is in use. In this case, the `.diamond-sr-only` class can be used to visually hide the label.',
},
},
};
1 change: 1 addition & 0 deletions styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@import url('./base/scaffolding.css');
@import url('./base/typography.css');
@import url('./base/interactive.css');
@import url('./base/screen-reader.css');
10 changes: 10 additions & 0 deletions styles/base/screen-reader.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.diamond-sr-only {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
3 changes: 2 additions & 1 deletion styles/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
@import url('./tokens/color.css');
@import url('./tokens/font.css');
@import url('./tokens/input.css');
@import url('./tokens/label.css');
@import url('./tokens/radius.css');
@import url('./tokens/theme.css');
@import url('./tokens/shadow.css');
@import url('./tokens/spacing.css');
@import url('./tokens/theme.css');
@import url('./tokens/transition.css');
@import url('./tokens/wrap.css');
6 changes: 6 additions & 0 deletions styles/tokens/label.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:root {
--diamond-label-color: var(--diamond-theme-color);
--diamond-label-font-weight: var(--diamond-font-weight-base);
--diamond-label-font-size: var(--diamond-font-size-base);
--diamond-label-height: var(--diamond-spacing-thumb);
}

0 comments on commit 38f2ec1

Please sign in to comment.