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

♻️ refactor(select): create option component #1356

Merged
merged 14 commits into from
Mar 18, 2024
5 changes: 5 additions & 0 deletions .changeset/ten-teachers-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': minor
---

**option**: new child component of option-list. Option list component will be used by drop-down, combobox and autocomplete.
2 changes: 1 addition & 1 deletion .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload snapshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: cypress-snapshots
path: e2e/cypress/snapshots

- name: Commit base images
if: success()
uses: EndBug/add-and-commit@v9
with:
message: 'update base images'
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ libs/output-targets-vue/CHANGELOG.md
e2e/generated
e2e/downloads
e2e/reg.json
e2e/cypress/snapshots
!e2e/cypress/snapshots/base
e2e/cypress/snapshots/actual
e2e/cypress/snapshots/diff

resources/data
!resources/data/tags.json
Expand Down
12 changes: 12 additions & 0 deletions docs/stories/components/bal-option/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Testing

The Baloise Design System provides a collection of custom cypress commands for the components. Moreover, some basic cypress commands like `should` or `click` have been overridden to work with the components.

<a class="sb-unstyled button is-primary" href="../?path=/docs/development-testing--documentation">Go to testing guide</a>

<!-- START: human documentation -->



<!-- END: human documentation -->

32 changes: 32 additions & 0 deletions docs/stories/components/bal-option/theming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Theming

The component can be customization by changing the CSS variables.

<a class="sb-unstyled button is-primary" href="../?path=/docs/development-theming--page">Go to theming guide</a>

<!-- START: human documentation -->



<!-- END: human documentation -->

### Variables​

| Variable |
| ------------------------------------------ |
| `--bal-option-padding-x` |
| `--bal-option-min-height` |
| `--bal-option-background` |
| `--bal-option-background-hovered` |
| `--bal-option-background-selected` |
| `--bal-option-background-selected-hovered` |
| `--bal-option-background-invalid` |
| `--bal-option-background-invalid-hovered` |
| `--bal-option-border-width` |
| `--bal-option-border-color` |
| `--bal-option-font-family` |
| `--bal-option-font-weight` |
| `--bal-option-line-height` |
| `--bal-option-text-hovered` |
| `--bal-option-text-pressed` |
| `--bal-option-text-disabled` |
13 changes: 13 additions & 0 deletions e2e/cypress/e2e/a11y/bal-option.a11y.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('bal-option', () => {
context('a11y', () => {
beforeEach(() => cy.platform('desktop').pageA11y('/components/bal-option/test/bal-option.a11y.html'))

describe('have the AA standard', () => {
it('basic', () => cy.getByTestId('basic').testA11y())
it('selected', () => cy.getByTestId('selected').testA11y())
it('focused', () => cy.getByTestId('focused').testA11y())
it('invalid', () => cy.getByTestId('invalid').testA11y())
it('disabled', () => cy.getByTestId('disabled').testA11y())
})
})
})
17 changes: 17 additions & 0 deletions e2e/cypress/e2e/visual/bal-option.visual.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('bal-option', () => {
describe('basic', () => {
beforeEach(() => cy.visit('/components/bal-option/test/bal-option.visual.html').waitForDesignSystem())

it('basic component', () => {
cy.getByTestId('basic').testVisual('option-basic')
})

it('listbox', () => {
cy.getByTestId('listbox').testVisual('option-listbox')
})

it('listbox-with-checkboxes', () => {
cy.getByTestId('listbox-checkbox').testVisual('option-listbox-checkbox')
})
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions e2e/cypress/support/lib/visuals/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export type CypressConfigEnv = {

/** Add custom cypress command to compare image snapshots of an element or the window. */
function addCompareSnapshotCommand(screenshotOptions?: ScreenshotOptions): void {
console.log('')
console.log('visualRegressionType => ', Cypress.env('visualRegressionType'))
console.log('')

Cypress.Commands.add(
'testVisual',
{ prevSubject: 'optional' },
Expand Down
110 changes: 110 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,48 @@ export namespace Components {
*/
"value"?: number;
}
interface BalOption {
/**
* If `true`, the user cannot interact with the option.
*/
"checkbox": boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"disabled": boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"focused": boolean;
/**
* If `true`, the option is hidden.
*/
"hidden": boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"invalid": boolean;
/**
* Label will be shown in the input element when it got selected
*/
"label": string;
/**
* If `true`, the user cannot interact with the option.
*/
"multiline": boolean;
/**
* Selects or deselects the option and informs other components
*/
"select": (selected?: boolean) => Promise<void>;
/**
* If `true`, the user cannot interact with the option.
*/
"selected": boolean;
/**
* The value of the select option. This value will be returned by the parent `<bal-select>` element.
*/
"value": string;
}
interface BalPagination {
/**
* Align the buttons to start, center or end
Expand Down Expand Up @@ -3332,6 +3374,10 @@ export interface BalNumberInputCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBalNumberInputElement;
}
export interface BalOptionCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBalOptionElement;
}
export interface BalPaginationCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBalPaginationElement;
Expand Down Expand Up @@ -4208,6 +4254,24 @@ declare global {
prototype: HTMLBalNumberInputElement;
new (): HTMLBalNumberInputElement;
};
interface HTMLBalOptionElementEventMap {
"balOptionChange": BalEvents.BalOptionChangeDetail;
"balOptionFocus": BalEvents.BalOptionFocusDetail;
}
interface HTMLBalOptionElement extends Components.BalOption, HTMLStencilElement {
addEventListener<K extends keyof HTMLBalOptionElementEventMap>(type: K, listener: (this: HTMLBalOptionElement, ev: BalOptionCustomEvent<HTMLBalOptionElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLBalOptionElementEventMap>(type: K, listener: (this: HTMLBalOptionElement, ev: BalOptionCustomEvent<HTMLBalOptionElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
var HTMLBalOptionElement: {
prototype: HTMLBalOptionElement;
new (): HTMLBalOptionElement;
};
interface HTMLBalPaginationElementEventMap {
"balChange": BalEvents.BalPaginationChangeDetail;
}
Expand Down Expand Up @@ -4704,6 +4768,7 @@ declare global {
"bal-notices": HTMLBalNoticesElement;
"bal-notification": HTMLBalNotificationElement;
"bal-number-input": HTMLBalNumberInputElement;
"bal-option": HTMLBalOptionElement;
"bal-pagination": HTMLBalPaginationElement;
"bal-popover": HTMLBalPopoverElement;
"bal-popover-content": HTMLBalPopoverContentElement;
Expand Down Expand Up @@ -6902,6 +6967,49 @@ declare namespace LocalJSX {
*/
"value"?: number;
}
interface BalOption {
/**
* If `true`, the user cannot interact with the option.
*/
"checkbox"?: boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"disabled"?: boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"focused"?: boolean;
/**
* If `true`, the option is hidden.
*/
"hidden"?: boolean;
/**
* If `true`, the user cannot interact with the option.
*/
"invalid"?: boolean;
/**
* Label will be shown in the input element when it got selected
*/
"label"?: string;
/**
* If `true`, the user cannot interact with the option.
*/
"multiline"?: boolean;
/**
* Emitted when the option gets selected or unselected
*/
"onBalOptionChange"?: (event: BalOptionCustomEvent<BalEvents.BalOptionChangeDetail>) => void;
"onBalOptionFocus"?: (event: BalOptionCustomEvent<BalEvents.BalOptionFocusDetail>) => void;
/**
* If `true`, the user cannot interact with the option.
*/
"selected"?: boolean;
/**
* The value of the select option. This value will be returned by the parent `<bal-select>` element.
*/
"value"?: string;
}
interface BalPagination {
/**
* Align the buttons to start, center or end
Expand Down Expand Up @@ -8156,6 +8264,7 @@ declare namespace LocalJSX {
"bal-notices": BalNotices;
"bal-notification": BalNotification;
"bal-number-input": BalNumberInput;
"bal-option": BalOption;
"bal-pagination": BalPagination;
"bal-popover": BalPopover;
"bal-popover-content": BalPopoverContent;
Expand Down Expand Up @@ -8275,6 +8384,7 @@ declare module "@stencil/core" {
"bal-notices": LocalJSX.BalNotices & JSXBase.HTMLAttributes<HTMLBalNoticesElement>;
"bal-notification": LocalJSX.BalNotification & JSXBase.HTMLAttributes<HTMLBalNotificationElement>;
"bal-number-input": LocalJSX.BalNumberInput & JSXBase.HTMLAttributes<HTMLBalNumberInputElement>;
"bal-option": LocalJSX.BalOption & JSXBase.HTMLAttributes<HTMLBalOptionElement>;
"bal-pagination": LocalJSX.BalPagination & JSXBase.HTMLAttributes<HTMLBalPaginationElement>;
"bal-popover": LocalJSX.BalPopover & JSXBase.HTMLAttributes<HTMLBalPopoverElement>;
"bal-popover-content": LocalJSX.BalPopoverContent & JSXBase.HTMLAttributes<HTMLBalPopoverContentElement>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../interfaces.d.ts" />

namespace BalProps {}

namespace BalEvents {
export interface BalOptionCustomEvent<T> extends CustomEvent<T> {
detail: T
target: HTMLBalOptionElement
}

export interface BalOption {
value: string
label: string
selected: boolean
}

export type BalOptionFocusDetail = BalOption
export type BalOptionFocus = BalOptionCustomEvent<BalOptionFocusDetail>

export type BalOptionBlurDetail = FocusEvent
export type BalOptionBlur = BalOptionCustomEvent<BalOptionBlurDetail>

export type BalOptionChangeDetail = BalOption
export type BalOptionChange = BalOptionCustomEvent<BalOptionChangeDetail>
}
Loading