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: add segmented-button #1429

Merged
merged 3 commits into from
Jan 25, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Segment should match standard snapshot 1`] = `
<button aria-description="deselected" class="segment segment--small" id="segment-0" part="segment small" type="button">
<div class="segment--mask">
<div class="success-icon-container">
<scale-icon-action-success accessibility-title="success" class="scale-icon-action-success" selected="" size="14"></scale-icon-action-success>
<scale-icon-action-success aria-hidden="true" class="scale-icon-action-success" selected="" size="14"></scale-icon-action-success>
</div>
<div class="icon-container">
<slot name="segment-icon"></slot>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/segment/segment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Segment {
<scale-icon-action-success
size={this.size === 'small' ? 14 : 16}
class="scale-icon-action-success"
accessibility-title="success"
aria-hidden="true"
selected
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export class SegmentedButton {
return -1;
} else {
const allSegments = this.getAllSegments();
const selectedIndex = allSegments.findIndex((el) => el.selected === true);
const selectedIndex = allSegments.findIndex(
(el: HTMLScaleSegmentElement) => el.selected === true
);
return selectedIndex;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ export const InvalidTemplate = (args, { argTypes }) => ({
</Canvas>

```html
<scale-segmented-button multi-select disabled>
<scale-segment>Apple</scale-segment>
<scale-segment>One+</scale-segment>
<scale-segment selected>Samsung</scale-segment>
<scale-segmented-button multi-select>
<scale-segment selected>Apple</scale-segment>
<scale-segment selected>One+</scale-segment>
<scale-segment>Samsung</scale-segment>
<scale-segment>Huawei</scale-segment>
</scale-segmented-button>
```
Expand Down Expand Up @@ -257,26 +257,22 @@ export const InvalidTemplate = (args, { argTypes }) => ({

```html
<scale-segmented-button>
<scale-segment selected
><scale-icon-weather-cloudy
slot="segment-icon"
></scale-icon-weather-cloudy
></scale-segment>
<scale-segmented-button
><scale-icon-weather-rain
slot="segment-icon"
></scale-icon-weather-rain
></scale-segment>
<scale-segmented-button
><scale-icon-weather-sunny
slot="segment-icon"
></scale-icon-weather-sunny
></scale-segment>
<scale-segmented-button
><scale-icon-weahter-heavy-snow
slot="segment-icon"
></scale-icon-weahter-heavy-snow
></scale-segment>
<scale-segment selected>
<scale-icon-weather-cloudy slot="segment-icon">
</scale-icon-weather-cloudy>
</scale-segment>
<scale-segment>
<scale-icon-weather-rain slot="segment-icon">
</scale-icon-weather-rain>
</scale-segment>
<scale-segment>
<scale-icon-weather-sunny slot="segment-icon">
</scale-icon-weather-sunny>
</scale-segment>
<scale-segment>
<scale-icon-weahter-heavy-snow slot="segment-icon">
</scale-icon-weahter-heavy-snow>
</scale-segment>
</scale-segmented-button>
```

Expand All @@ -290,30 +286,26 @@ export const InvalidTemplate = (args, { argTypes }) => ({

```html
<scale-segmented-button>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Apple</scale-segmented-button
>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>One+</scale-segmented-button
>
<scale-segment selected
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Samsung</scale-segmented-button
>
<scale-segment selected
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Huawei</scale-segmented-button
>
<scale-segment selected>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Apple
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
One+
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Samsung
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Huawei
</scale-segment>
</scale-segmented-button>
```

Expand All @@ -332,29 +324,25 @@ export const InvalidTemplate = (args, { argTypes }) => ({

```html
<scale-segmented-button invalid>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Apple</scale-segmented-button
>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>One+</scale-segmented-button
>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Samsung</scale-segmented-button
>
<scale-segmented-button
><scale-icon-device-device-phone
slot="segment-icon"
></scale-icon-device-device-phone
>Huawei</scale-segmented-button
>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Apple
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
One+
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Samsung
</scale-segment>
<scale-segment>
<scale-icon-device-device-phone slot="segment-icon">
</scale-icon-device-device-phone>
Huawei
</scale-segment>
</scale-segmented-button>
```