Skip to content

Commit d946c7a

Browse files
authored
Add border utilities (#1853)
1 parent 0b96766 commit d946c7a

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

.changeset/rare-trainers-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add border utilities

src/base/_defaults.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ del {
181181
/**
182182
* IE10 and earlier still show borders around linked images, and all browsers
183183
* still show borders around iframe elements by default.
184+
*
185+
* We set the `border-style` and `border-width` so that utility classes can
186+
* easily set themed default colors.
184187
*/
185188

186189
iframe,
187190
img {
188-
border-style: none;
191+
border-style: solid;
192+
border-width: 0;
189193
}
190194

191195
/**

src/base/_themes.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
--theme-color-background-base: #{color.$text-light-emphasis};
1717
--theme-color-background-kbd: transparent;
1818
--theme-color-background-secondary: #{color.$base-gray-lighter};
19-
--theme-color-border-kbd: #{color.$base-gray-light};
20-
--theme-color-border-text-group: #{color.$base-gray-light};
19+
--theme-color-border-base: #{color.$base-gray-light};
20+
--theme-color-border-kbd: var(--theme-color-border-base);
21+
--theme-color-border-text-group: var(--theme-color-border-base);
2122
--theme-color-text-action: #{color.$text-action};
2223
--theme-color-text-base: #{color.$text-dark};
2324
--theme-color-text-code: #{color.$base-fuchsia};
@@ -34,8 +35,9 @@
3435
--theme-color-background-base: #{color.$brand-primary};
3536
--theme-color-background-kbd: #{color.$brand-primary-dark};
3637
--theme-color-background-secondary: #{color.$brand-primary-dark};
37-
--theme-color-border-kbd: #{color.$brand-primary-darker};
38-
--theme-color-border-text-group: #{color.$brand-primary-darker};
38+
--theme-color-border-base: #{color.$brand-primary-darker};
39+
--theme-color-border-kbd: var(--theme-color-border-base);
40+
--theme-color-border-text-group: var(--theme-color-border-base);
3941
--theme-color-text-action: var(--theme-color-text-emphasis);
4042
--theme-color-text-base: #{color.$text-light};
4143
--theme-color-text-code: var(--theme-color-text-emphasis);

src/utilities/border/border.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@use '../../compiled/tokens/scss/size';
2+
3+
/**
4+
* To improve the convenience of using these classes without having to specify
5+
* a border style and color every time, we use the `:where` selector to set some
6+
* reasonable defaults with no specificity depth.
7+
*/
8+
9+
:where([class^='u-border'], [class*=' u-border']) {
10+
border-color: var(--theme-color-border-text-group);
11+
border-style: solid;
12+
}
13+
14+
/**
15+
* Sizes
16+
*/
17+
18+
.u-border,
19+
.u-border-small {
20+
border-width: size.$edge-small !important;
21+
}
22+
23+
.u-border-medium {
24+
border-width: size.$edge-medium !important;
25+
}
26+
27+
.u-border-large {
28+
border-width: size.$edge-large !important;
29+
}
30+
31+
.u-border-none {
32+
border-width: 0 !important;
33+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Story, Canvas, Meta } from '@storybook/addon-docs';
2+
const borderStory = (args) => {
3+
const classNames = [args.width || ''];
4+
if (args.color) {
5+
classNames.push(args.color);
6+
}
7+
const className = classNames
8+
.map((segment) => (segment.length > 0 ? `u-border-${segment}` : 'u-border'))
9+
.join(' ');
10+
return `<div class="${className} u-pad-n1">${className}</div>`;
11+
};
12+
13+
<Meta
14+
title="Utilities/Border"
15+
argTypes={{
16+
width: {
17+
options: ['small', 'medium', 'large', 'none'],
18+
type: { name: 'enum' },
19+
control: { type: 'inline-radio' },
20+
},
21+
}}
22+
/>
23+
24+
# Border
25+
26+
These utilities apply borders. They may be used to visually offset content from its surroundings. For example, a screenshot in an article with a white background might blend in too much with the page without a border.
27+
28+
## Sizes
29+
30+
Available sizes are based on [our `size.$edge-` tokens](/?path=/docs/design-tokens-size--page#edge):
31+
32+
- `u-border` or `u-border-small`
33+
- `u-border-medium`
34+
- `u-border-large`
35+
36+
<Canvas>
37+
<Story name="Small (Default)">{(args) => borderStory(args)}</Story>
38+
<Story name="Medium" args={{ width: 'medium' }}>
39+
{(args) => borderStory(args)}
40+
</Story>
41+
<Story name="Large" args={{ width: 'large' }}>
42+
{(args) => borderStory(args)}
43+
</Story>
44+
<Story name="None" args={{ width: 'none' }}>
45+
{(args) => borderStory(args)}
46+
</Story>
47+
</Canvas>
48+
49+
## Color and style
50+
51+
If no `border-color` is set, these utilities will use the default border color of the current [theme](/?path=/docs/design-themes--light). If no `border-style` is set, the utility will use `solid`.
52+
53+
We may add specific color and style utilities in the future as the need arises.

0 commit comments

Comments
 (0)