Skip to content

feat(segmented-button): add icon and text support #5529

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-days-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': minor
Copy link
Contributor

Choose a reason for hiding this comment

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

You also changed the styles package.

---

added a version with an icon to the segmented button.
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
added a version with an icon to the segmented button.
Added a version with an icon to the segmented button.

Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ It allows users to toggle between two or more content sections within the same a
<Canvas of={SegmentedButtonStories.IconExample} sourceState="shown" />
<Controls of={SegmentedButtonStories.IconExample} />

## Segmented text and icon button

<Canvas of={SegmentedButtonStories.TextAndIconExample} sourceState="shown" />
<Controls of={SegmentedButtonStories.TextAndIconExample} />

<StylesPackageImport components={['segmented-button']} />
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StoryObj } from '@storybook/web-components';
import meta from './segmented-button.stories';
import { html } from 'lit';
import { html, nothing } from 'lit'; // ← ajout de `nothing`
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
import { html, nothing } from 'lit'; // ← ajout de `nothing`
import { html, nothing } from 'lit';

import { schemes } from '@/shared/snapshots/schemes';

const { id, ...metaWithoutId } = meta;
Expand Down Expand Up @@ -37,6 +37,23 @@ export const SegmentedButton: Story = {
</div>
`;
})}
${labelCounts.map(count => {
const labels = Array.from({ length: count }, (_, i) => `Label ${i + 1}`);
const name = `text-icon-${count}-${scheme}`;
return html`
<fieldset class="segmented-button">
${labels.map(
(label, index) => html`
<label class="segmented-button-label">
<input type="radio" name="${name}" />
<post-icon name="${1000 + index}"></post-icon>
${label}
</label>
`,
)}
</fieldset>
`;
})}
</div>
`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,28 @@ export const IconExample: Story = {
`;
},
};

export const TextAndIconExample: Story = {
render: (args: Args) => {
const labelCount = Math.min(args.labelCount || 0, MAX_LABELS);
const labelsArray = Array.from({ length: labelCount }, (_, i) => `Label ${i + 1}`);
const name = `segmented-button-${Math.random().toString(36).slice(-6)}`;

return html`
<div class="segmented-button-container">
<fieldset class="segmented-button">
<legend>Choose one of the options</legend>
${labelsArray.map(
(label, index) => html`
<label class="segmented-button-label">
<input type="radio" name="${name}" checked="${index === 0 ? '' : nothing}" />
<post-icon name="${1000 + index}"></post-icon>
${label}
</label>
`,
)}
</fieldset>
</div>
`;
},
};
1 change: 1 addition & 0 deletions packages/styles/src/components/segmented-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $post-segmented-button-max-count: 8;
label {
flex: 0 1 100%;
display: flex;
gap: tokens.get('button-segmented-gap-inline');
justify-content: center;
align-items: center;
position: relative;
Expand Down
1 change: 1 addition & 0 deletions packages/styles/src/utilities/_post-icon-version.scss
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change necessary?

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$post-icon-version: '9.0.0-next.36';
196 changes: 98 additions & 98 deletions pnpm-lock.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

You did not add or remove libraries, there shouldn't be any changes to the lock file.

Large diffs are not rendered by default.

Loading