-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: main
Are you sure you want to change the base?
Changes from all commits
261c583
699a336
10b6aa8
b0997ee
de36a66
74a5cd5
d1d64b4
603a143
5e4d0c5
f9f144b
14ad298
ad91841
8289085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@swisspost/design-system-styles': minor | ||
'@swisspost/design-system-documentation': minor | ||
--- | ||
|
||
Internalized bootstraps floating utilities into the design system. |
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] }); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Canvas, Controls, Meta, Source } from '@storybook/blocks'; | ||
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> | ||
|
||
> - `float-sm-{start|end|none}` | ||
> - `float-md-{start|end|none}` | ||
> - `float-lg-{start|end|none}` | ||
> - `float-xl-{start|end|none}` | ||
> - `float-xxl-{start|end|none}` | ||
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Args, StoryContext, StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
import meta from './float.stories'; | ||
import { bombArgs } from '@/utils'; | ||
|
||
const { id, ...metaWithoutId } = meta; | ||
|
||
export default { | ||
...metaWithoutId, | ||
title: 'Snapshots', | ||
}; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Float: Story = { | ||
render: (_args: Args, context: StoryContext) => { | ||
return html` | ||
<div class="snapshot-example"> | ||
<h1>Snapshot with Float</h1> | ||
${['bg-white', 'bg-dark'].map( | ||
bg => html` | ||
<div class="${bg} p-16"> | ||
${(meta.argTypes?.floatBreakPoint?.options ?? []).map((breakpoint: string) => { | ||
return html` | ||
<h2>Breakpoint ${breakpoint}</h2> | ||
<div> | ||
${bombArgs({ | ||
floatPosition: [...(meta.argTypes?.floatPosition?.options ?? [])], | ||
floatBreakPoint: [breakpoint], | ||
}).map((args: Args) => { | ||
return html` | ||
<div class="clearfix"> | ||
${meta.render?.({ ...context.args, ...args, breakpoint }, context)} | ||
</div> | ||
`; | ||
})} | ||
</div> | ||
`; | ||
})} | ||
</div> | ||
`, | ||
)} | ||
</div> | ||
`; | ||
}, | ||
}; |
myrta2302 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,64 @@ | ||||||
import type { Args, StoryObj, StoryFn, StoryContext } 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 { nothing } from 'lit'; | ||||||
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ | ||||||
|
||||||
const meta: MetaExtended = { | ||||||
id: 'ccf092c1-f0ab-49a1-a612-87e5be23adde', | ||||||
title: 'Utilities/Float', | ||||||
argTypes: { | ||||||
floatPosition: { | ||||||
name: 'float', | ||||||
description: 'Sets the float. ', | ||||||
control: { | ||||||
type: 'select', | ||||||
}, | ||||||
options: ['start', 'end', 'none'], | ||||||
table: { | ||||||
category: 'Add float', | ||||||
}, | ||||||
}, | ||||||
floatBreakPoint: { | ||||||
name: 'breakpoint', | ||||||
description: 'Sets the float for a specific breakpoint. ', | ||||||
control: { | ||||||
type: 'select', | ||||||
}, | ||||||
options: ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'], | ||||||
table: { | ||||||
category: 'Add float', | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
args: { | ||||||
floatPosition: null, | ||||||
floatBreakPoint: null, | ||||||
}, | ||||||
render: (args: Args) => { | ||||||
const classMembers = ['float', args.floatBreakPoint ?? 'xs', args.floatPosition].filter(m => m); | ||||||
const floatClass = | ||||||
classMembers.length === 3 ? classMembers.filter(m => m !== 'xs').join('-') : nothing; | ||||||
|
||||||
return html` | ||||||
<div class="${floatClass}"> | ||||||
Sample Text ${args.floatPosition ? '(float-' + args.floatPosition + ')' : ''} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for adding a CR for this again, but it would be helpful to also know on which breakpoint the content should be floated.
Suggested change
|
||||||
</div> | ||||||
`; | ||||||
}, | ||||||
decorators: [ | ||||||
(story: StoryFn, context: StoryContext) => { | ||||||
const storyTemplate = html`<div class="clearfix float-example"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this obsolete class
Suggested change
|
||||||
${story(context.args, context)} | ||||||
</div>`; | ||||||
return storyTemplate; | ||||||
}, | ||||||
], | ||||||
}; | ||||||
|
||||||
export default meta; | ||||||
|
||||||
type Story = StoryObj; | ||||||
|
||||||
export const Float: Story = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.