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(sbb-paginator): add disabled property #3130

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 29 additions & 3 deletions src/elements/paginator/paginator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
--sbb-paginator-page-border-width: 0;
--sbb-paginator-page-border-style: none;
--sbb-paginator-page-border-color: none;
--sbb-paginator-page-cursor: pointer;
--sbb-paginator-page-inset: 0;
--sbb-paginator-animation-easing: var(--sbb-animation-easing);
--sbb-paginator-animation-duration: var(
Expand Down Expand Up @@ -97,7 +98,7 @@
@include sbb.text-s--regular;

position: relative;
cursor: pointer;
cursor: var(--sbb-paginator-page-cursor);
outline: none !important;
color: var(--sbb-paginator-page-color);
transition: color var(--sbb-paginator-animation-duration) var(--sbb-paginator-animation-easing);
Expand Down Expand Up @@ -146,7 +147,32 @@
}
}

&:hover {
&:disabled {
--sbb-paginator-page-color: var(--sbb-color-smoke);
--sbb-paginator-page-border-width: var(--sbb-border-width-1x);
--sbb-paginator-page-border-style: dashed;
--sbb-paginator-page-border-color: var(--sbb-color-smoke);
--sbb-paginator-page-background-color: var(--sbb-color-milk);
--sbb-paginator-page-cursor: default;

&[data-selected] {
--sbb-paginator-page-border-width: var(--sbb-border-width-2x);
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
}

@include sbb.if-forced-colors {
--sbb-paginator-page-border-color: GrayText;
--sbb-paginator-page-color: GrayText;
--sbb-paginator-page-background-color: Canvas;
}

:host([negative]) & {
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
--sbb-paginator-page-color: var(--sbb-color-aluminium);
--sbb-paginator-page-border-style: dashed;
--sbb-paginator-page-background-color: var(--sbb-color-anthracite);
}
}

&:not(:disabled):hover {
@include sbb.hover-mq($hover: true) {
--sbb-paginator-page-background-color: var(--sbb-color-milk);
--sbb-paginator-page-inset: calc(var(--sbb-border-width-2x) * -1);
Expand All @@ -162,7 +188,7 @@
}
}

&:active {
&:not(:disabled):active {
--sbb-paginator-page-color: var(--sbb-color-charcoal);
--sbb-paginator-page-background-color: var(--sbb-color-cloud);
--sbb-paginator-page-inset: 0;
Expand Down
25 changes: 25 additions & 0 deletions src/elements/paginator/paginator.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const negative: InputType = {
},
};

const disabled: InputType = {
control: {
type: 'boolean',
},
};

const defaultArgTypes: ArgTypes = {
length,
'page-size': pageSize,
Expand All @@ -76,6 +82,7 @@ const defaultArgTypes: ArgTypes = {
'pager-position': pagerPosition,
size,
negative,
disabled,
};

const defaultArgs: Args = {
Expand All @@ -86,6 +93,7 @@ const defaultArgs: Args = {
'pager-position': pagerPosition.options![0],
size: size.options![0],
negative: false,
disabled: false,
};

const Template = ({ pageSizeOptions, ...args }: Args): TemplateResult => {
Expand All @@ -108,6 +116,12 @@ export const Negative: StoryObj = {
args: { ...defaultArgs, negative: true },
};

export const Disabled: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, disabled: true },
};

export const SizeS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
Expand All @@ -126,6 +140,17 @@ export const WithPageSizeOptions: StoryObj = {
args: { ...defaultArgs, length: 1000, pageSizeOptions: pageSizeOptions.options![1] },
};

export const WithPageSizeOptionsDisabled: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: {
...defaultArgs,
length: 1000,
disabled: true,
pageSizeOptions: pageSizeOptions.options![1],
},
};

export const WithPageSizeOptionsNegative: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
Expand Down
10 changes: 6 additions & 4 deletions src/elements/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
i18nPreviousPage,
i18nSelectedPage,
} from '../core/i18n.js';
import { SbbNegativeMixin } from '../core/mixins.js';
import { SbbDisabledMixin, SbbNegativeMixin } from '../core/mixins.js';
import type { SbbSelectElement } from '../select.js';

import style from './paginator.scss?lit&inline';
Expand Down Expand Up @@ -53,7 +53,7 @@ let nextId = 0;
@hostAttributes({
role: 'group',
})
export class SbbPaginatorElement extends SbbNegativeMixin(LitElement) {
export class SbbPaginatorElement extends SbbNegativeMixin(SbbDisabledMixin(LitElement)) {
public static override styles: CSSResultGroup = style;
public static readonly events: Record<string, string> = {
page: 'page',
Expand Down Expand Up @@ -275,15 +275,15 @@ export class SbbPaginatorElement extends SbbNegativeMixin(LitElement) {
id="sbb-paginator-prev-page"
aria-label=${i18nPreviousPage[this._language.current]}
icon-name="chevron-small-left-small"
?disabled=${this.pageIndex === 0}
?disabled=${this.disabled || this.pageIndex === 0}
@click=${() => this._pageIndexChanged(this._pageIndex - 1)}
></sbb-mini-button>
<sbb-divider orientation="vertical"></sbb-divider>
<sbb-mini-button
id="sbb-paginator-next-page"
aria-label=${i18nNextPage[this._language.current]}
icon-name="chevron-small-right-small"
?disabled=${this.pageIndex === this._numberOfPages() - 1}
?disabled=${this.disabled || this.pageIndex === this._numberOfPages() - 1}
@click=${() => this._pageIndexChanged(this._pageIndex + 1)}
></sbb-mini-button>
</sbb-mini-button-group>
Expand All @@ -308,6 +308,7 @@ export class SbbPaginatorElement extends SbbNegativeMixin(LitElement) {
this.pageSizeOptions![0]}
@change=${(e: CustomEvent) =>
this._pageSizeChanged(+((e.target as SbbSelectElement).value as string))}
?disabled=${this.disabled}
>
${repeat(
this.pageSizeOptions!,
Expand Down Expand Up @@ -336,6 +337,7 @@ export class SbbPaginatorElement extends SbbNegativeMixin(LitElement) {
<li class="sbb-paginator__page--number">
<button
?data-selected=${this.pageIndex === item}
?disabled=${this.disabled}
class="sbb-paginator__page--number-item"
data-index=${item}
aria-label="${i18nPage[this._language.current]} ${item + 1}"
Expand Down
10 changes: 10 additions & 0 deletions src/elements/paginator/paginator.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe('sbb-paginator', () => {
}
});
}

it(
'disabled=true',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-paginator length="100" disabled ?negative=${negative}></sbb-paginator>`,
{ ...wrapperStyle, forcedColors },
);
}),
);
});
}

Expand Down
9 changes: 9 additions & 0 deletions src/elements/paginator/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ The dropdown menu and the previous / next buttons are facing each other with the
<sbb-paginator length="100" page-size="20" page-size-options="[10, 20, 50]"></sbb-paginator>
```

## States

The component can be disabled by using the `disabled` property.

```html
<sbb-paginator length="100" page-size="20" disabled></sbb-paginator>
```

## Style

The component has two `size`, named `s` and `m` (default).
Expand Down Expand Up @@ -59,6 +67,7 @@ that describes the content controlled by the paginator.

| Name | Attribute | Privacy | Type | Default | Description |
| ----------------- | ------------------- | ------- | ----------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `disabled` | `disabled` | public | `boolean` | `false` | Whether the component is disabled. |
| `length` | `length` | public | `number` | `0` | Total number of items. |
| `negative` | `negative` | public | `boolean` | `false` | Negative coloring variant flag. |
| `pageIndex` | `page-index` | public | `number` | `0` | Current page index. |
Expand Down
Loading