Skip to content

Commit

Permalink
feat(switch): add change event to storybook and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-iden committed Oct 29, 2024
1 parent 5d19914 commit aba3e12
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PharosSwitch } from '../../react-components/switch/pharos-switch';
import { configureDocsPage } from '@config/docsPageConfig';
import { PharosContext } from '../../utils/PharosContext';
import { action } from '@storybook/addon-actions';

export default {
title: 'Forms/Switch',
Expand All @@ -22,12 +23,19 @@ export default {

export const Base = {
render: ({ disabled, checked }) => (
<PharosSwitch disabled={disabled} checked={checked}>
<PharosSwitch
disabled={disabled}
checked={checked}
onChange={(e) => action('Change')(e.target.checked)}
>
<span slot="label">Toggle Switch</span>
</PharosSwitch>
),
args: {
disabled: false,
checked: false,
},
parameters: {
options: { selectedPanel: 'addon-actions' },
},
};
5 changes: 2 additions & 3 deletions packages/pharos/src/components/switch/pharos-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { property, query } from 'lit/decorators.js';
*
* @tag pharos-switch
*
* @fires change - Fires when the value has changed
*/
export class PharosSwitch extends FormMixin(FormElement) {
/**
Expand Down Expand Up @@ -38,11 +39,9 @@ export class PharosSwitch extends FormMixin(FormElement) {
}

private _handleClick(event: Event): void {
console.log('handle click??', this.checked);
event.preventDefault();
event.stopPropagation();
this._switch.click();
// this._switch.focus();
}

public onChange(): void {
Expand Down Expand Up @@ -102,7 +101,7 @@ export class PharosSwitch extends FormMixin(FormElement) {
<label for="switch-element" class="switch__label" @click="${this._handleClick}">
<slot name="label"></slot>
</label>
<span class="switch__control" @click="${this._handleClick}"></span>
<span class="switch__control" aria-hidden="true" @click="${this._handleClick}"></span>
</div>
</div>
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { html } from 'lit';
import { action } from '@storybook/addon-actions';

import { configureDocsPage } from '@config/docsPageConfig';

Expand All @@ -15,11 +16,17 @@ export default {

export const Base = {
render: ({ disabled, checked }) =>
html` <storybook-pharos-switch ?disabled=${disabled} ?checked=${checked}
html` <storybook-pharos-switch
?disabled=${disabled}
?checked=${checked}
@change="${(e) => action('Change')(e.target.checked)}"
><span slot="label">Toggle Switch</span></storybook-pharos-switch
>`,
args: {
disabled: false,
checked: false,
},
parameters: {
options: { selectedPanel: 'addon-actions' },
},
};

0 comments on commit aba3e12

Please sign in to comment.