Skip to content

Commit cd60b08

Browse files
authored
Add float utilities (#2177)
1 parent f27b66e commit cd60b08

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

.changeset/metal-crabs-pretend.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 float utilities
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% set float_class -%}
2+
u-float-{{float|default('none')}}
3+
{%- if breakpoint -%}
4+
@{{breakpoint}}
5+
{%- endif -%}
6+
{%- endset %}
7+
8+
<div class="{{float_class}} u-rounded t-dark u-pad-1">
9+
{{float_class}}
10+
</div>
11+
12+
<p>
13+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
14+
</p>

src/utilities/float/float.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@use '../../mixins/media-query';
2+
3+
// Set the float styles in a mixin. The suffix will let us easily append
4+
// breakpoint suffixes.
5+
@mixin _float-utilities($suffix: '') {
6+
.u-float-inline-start#{$suffix} {
7+
float: left;
8+
float: inline-start;
9+
}
10+
11+
.u-float-inline-end#{$suffix} {
12+
float: right;
13+
float: inline-end;
14+
}
15+
16+
.u-float-none#{$suffix} {
17+
float: none;
18+
}
19+
}
20+
21+
// Include the default versions (no media queries)
22+
@include _float-utilities;
23+
24+
// Include responsive versions. This would be simpler if we could use the
25+
// `breakpoint-classes` mixin instead, but in this case we want all of the
26+
// responsive versions to be grouped by breakpoint so larger breakpoints will
27+
// naturally override smaller ones.
28+
@include media-query.breakpoint-loop using ($key) {
29+
$suffix: \@#{$key};
30+
@include _float-utilities($suffix);
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2+
import floatDemo from './demo/float.twig';
3+
4+
<Meta
5+
title="Utilities/Float"
6+
argTypes={{
7+
float: {
8+
options: ['inline-start', 'inline-end', 'none'],
9+
control: {
10+
type: 'select',
11+
},
12+
},
13+
breakpoint: {
14+
options: ['xs', 's', 'm', 'l', 'xl', 'xxl', 'xxxl'],
15+
control: {
16+
type: 'inline-radio',
17+
},
18+
},
19+
}}
20+
/>
21+
22+
# Float
23+
24+
Utilities for controlling the float of an element. Useful for responsively arranging imagery or other content adjacent to medium-to-long sections of text.
25+
26+
## Flow-Relative Properties
27+
28+
These utilities use flow-relative values instead of specific directions [in supported browsers](https://caniuse.com/mdn-css_properties_float_flow_relative_values) to simplify potential localization projects.
29+
30+
The following table maps the traditional directional property for `direction: ltr` and `writing-mode: horizontal-tb` to its equivalent flow-relative property:
31+
32+
| Directional Property | Flow-relative Property |
33+
| -------------------- | ---------------------- |
34+
| `left` | `inline-start` |
35+
| `right` | `inline-end` |
36+
37+
## Float Direction
38+
39+
The following float utilities are available:
40+
41+
- `u-float-inline-start`
42+
- `u-float-inline-end`
43+
- `u-float-none`
44+
45+
Appending `@{breakpoint}` to the end of these class names (example: `u-float-inline-end@m`) will apply the float utility at the specified breakpoint and above.
46+
47+
<Canvas>
48+
<Story name="Direction" args={{ float: 'inline-end' }}>
49+
{(args) => floatDemo(args)}
50+
</Story>
51+
</Canvas>
52+
53+
<ArgsTable story="Direction" />

0 commit comments

Comments
 (0)