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

feat(styles): updated float utility #3752

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions .changeset/slimy-rockets-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@swisspost/design-system-styles': minor
'@swisspost/design-system-documentation': minor
---

Updated the utility classes for float
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Float', () => {
it('float', () => {
cy.visit('/iframe.html?id=snapshots--float');
cy.get('.float-example', { timeout: 30000 }).should('be.visible');
cy.percySnapshot('Float', { widths: [320, 1440] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.percySnapshot('Float', { widths: [320, 1440] });
cy.percySnapshot('Float', { widths: [320, 400, 600, 780, 1024, 1280, 1440] });

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Canvas, Controls, Meta, Source } from '@storybook/blocks';
import { formatAsMap } from '@/utils/sass-export';
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
import * as FloatStories from './float.stories';

<Meta of={FloatStories} />

# Float

<div className="lead">
Use `float-start`, `float-end`, or `float-none` to easily float elements.
</div>

## Properties

- `float-start`: Floats the element to the left (in LTR).
- `float-end`: Floats the element to the right (in LTR).
- `float-none`: Removes floating from the element.

### Relative to breakpoints

<div className="alert alert-info">
The `float-{breakpoint}-{position}` classes provide control over floating elements at specific
breakpoints, enabling you to float elements or remove floating based on the screen size.
</div>

> - `*-sm-*`
> - `*-md-*`
> - `*-lg-*`
> - `*-xl-*`
> - `*-xxl-*`
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved

#### Example

<Canvas sourceState="shown" of={FloatStories.Float} />
<div className="hide-col-default">
<Controls of={FloatStories.Float} />
</div>
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use '@swisspost/design-system-styles/core' as post;

:export {
@each $key, $value in post.$post-sizes {
#{$key}: #{$value};
}
}
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Args, StoryContext, StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import meta, { FloatSnapshot as F } from './float.stories';
import './float.styles.scss';

const { id, ...metaWithoutId } = meta;

export default {
...metaWithoutId,
title: 'Snapshots',
};

type Story = StoryObj;

export const Float: Story = {
render: (_args: Args, context: StoryContext) => {
const snapshotArgs = {
floatPosition: '',
floatBreakPoint: '',
};

return html`
<div class="float-example">${F.render?.({ ...F.args, ...snapshotArgs }, context)}</div>
`;
},
};
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { Args, StoryObj } from '@storybook/web-components';
import { html } from 'lit/static-html.js';
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
import { MetaExtended } from '@root/types';
import './float.styles.scss';

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

const meta: MetaExtended = {
id: 'ccf092c1-f0ab-49a1-a612-87e5be23adde',
title: 'Utilities/Float',
};

export default meta;

type Story = StoryObj;

export const Float: Story = {
argTypes: {
floatPosition: {
name: 'float',
description: 'Sets the float. ',
control: {
type: 'select',
},
options: ['start', 'end', 'none'],
table: {
category: 'Add float',
},
},
floatBreakPoint: {
name: 'float',
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
description: 'Sets the float for a specific breakpoint. ',
control: {
type: 'select',
},
options: ['', 'sm', 'md', 'lg', 'xl', 'xxl'],
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
table: {
category: 'Add float',
},
},
},
args: {
floatPosition: '',
floatBreakPoint: '',
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
},
render: (args: Args) => {
const float = args.floatPosition !== '' ? `float` : '';
const floatPosition = args.floatPosition !== '' ? `-${args.floatPosition}` : '';
const floatBreakPoint = args.floatBreakPoint !== '' ? `-${args.floatBreakPoint}` : '';
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved

return html`
<div class="float-example">
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
<div class="${float}${floatBreakPoint}${floatPosition}">Sample Text</div>
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
</div>
`;
},
};

export const FloatSnapshot: Story = {
render: () => {
const samples = [
['null', 'none'],
['null', 'start'],
['null', 'end'],
['sm', 'start'],
['md', 'end'],
['lg', 'none'],
['xl', 'start'],
['xxl', 'none'],
];

return html`
${samples.map(([floatBreakPoint, floatPosition]) => {
const fbp = floatBreakPoint !== 'null' ? `${floatBreakPoint}-` : '';
return html`
<div class="float-${fbp}${floatPosition}">Sample Text</div>
<div class="clearfix"></div>
`;
})}
`;
},
};
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use '@swisspost/design-system-styles/core' as post;

.float-example {
.content {
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
background-color: post.$white;
border: 1px solid post.$gray-40;
}
}
4 changes: 4 additions & 0 deletions packages/styles/src/themes/bootstrap/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ $utilities: map.remove($utilities, 'justify-content');

$utilities: map.remove($utilities, 'display');

$utilities: map.remove($utilities, 'float-start');
$utilities: map.remove($utilities, 'float-end');
$utilities: map.remove($utilities, 'float-none');

@import 'bootstrap/scss/utilities/api';
9 changes: 9 additions & 0 deletions packages/styles/src/utilities/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
*/

$utilities: (
'float': (
responsive: true,
property: float,
values: (
start: left,
end: right,
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
none: none,
),
),
'margin': (
responsive: true,
property: margin,
Expand Down