Skip to content

Commit

Permalink
fix: f2-switch-field docs has wrong example
Browse files Browse the repository at this point in the history
  • Loading branch information
teamchong authored and George-Payne committed Feb 21, 2025
1 parent d8d88a7 commit 0901959
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 57 deletions.
9 changes: 2 additions & 7 deletions packages/fields/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,7 @@ declare global {
new (): HTMLF2SwitchElement;
};
interface HTMLF2SwitchFieldElementEventMap {
"fieldchange": FieldChange<string>;
"enter": any;
"fieldchange": FieldChange<boolean>;
"requestEdit": string;
}
/**
Expand Down Expand Up @@ -2409,14 +2408,10 @@ declare namespace LocalJSX {
* The name of the field.
*/
"name": string;
/**
* Emitted on keyup of enter, if no modifier keys are held.
*/
"onEnter"?: (event: F2SwitchFieldCustomEvent<any>) => void;
/**
* Emitted when the value of the field is changed.
*/
"onFieldchange"?: (event: F2SwitchFieldCustomEvent<FieldChange<string>>) => void;
"onFieldchange"?: (event: F2SwitchFieldCustomEvent<FieldChange<boolean>>) => void;
/**
* Emitted when the user requests to edit.
*/
Expand Down
43 changes: 18 additions & 25 deletions packages/fields/src/components/switch/field/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# f2-text-field
# f2-switch-field

<!-- Auto Generated Below -->

Expand All @@ -15,35 +15,29 @@ A switch with a label.
import { createValidatedForm } from '@kurrent-ui/forms';

interface Example {
name: string | null;
notifications: boolean;
maintenance: boolean;
}

const form = createValidatedForm<Example>({
name: null,
notifications: true,
maintenance: false,
});

const options = [
{ name: 'Jim', value: 'jim' },
{ name: 'John', value: 'john' },
{ name: 'Nathanial', value: 'nathanial' },
];

export default () => (
<f2-form>
<f2-select-field
label={'Choose a name from the list'}
documentation={"It doesn't matter who it is."}
placeholder={'Choose a name from the list'}
options={options}
{...form.connect('name')}
<f2-switch-field
label={'Enable notifications'}
documentation={
'Receive real-time updates and alerts about system events'
}
{...form.connect('notifications')}
/>
<f2-select-field
<f2-switch-field
disabled
label={'Choose a name from the list'}
label={'Maintenance mode'}
documentation={'This field is disabled'}
placeholder={'Choose a name from the list'}
options={options}
{...form.connect('name')}
{...form.connect('maintenance')}
/>
</f2-form>
);
Expand Down Expand Up @@ -74,11 +68,10 @@ export default () => (

## Events

| Event | Description | Type |
| ------------- | -------------------------------------------------------- | ------------------------------------------ |
| `enter` | Emitted on keyup of enter, if no modifier keys are held. | `CustomEvent<any>` |
| `fieldchange` | Emitted when the value of the field is changed. | `CustomEvent<FieldChange<string, string>>` |
| `requestEdit` | Emitted when the user requests to edit. | `CustomEvent<string>` |
| Event | Description | Type |
| ------------- | ----------------------------------------------- | ------------------------------------------- |
| `fieldchange` | Emitted when the value of the field is changed. | `CustomEvent<FieldChange<boolean, string>>` |
| `requestEdit` | Emitted when the user requests to edit. | `CustomEvent<string>` |


## Shadow Parts
Expand Down
4 changes: 1 addition & 3 deletions packages/fields/src/components/switch/field/switch-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class SwitchField {
@AttachInternals() internals?: ElementInternals;

/** Emitted when the value of the field is changed. */
@Event({ bubbles: true }) fieldchange!: EventEmitter<FieldChange<string>>;
/** Emitted on keyup of enter, if no modifier keys are held. */
@Event() enter!: EventEmitter;
@Event({ bubbles: true }) fieldchange!: EventEmitter<FieldChange<boolean>>;
/** Emitted when the user requests to edit. */
@Event({ bubbles: true }) requestEdit!: EventEmitter<string>;

Expand Down
32 changes: 13 additions & 19 deletions packages/fields/src/components/switch/field/usage/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,29 @@
import { createValidatedForm } from '@kurrent-ui/forms';

interface Example {
name: string | null;
notifications: boolean;
maintenance: boolean;
}

const form = createValidatedForm<Example>({
name: null,
notifications: true,
maintenance: false,
});

const options = [
{ name: 'Jim', value: 'jim' },
{ name: 'John', value: 'john' },
{ name: 'Nathanial', value: 'nathanial' },
];

export default () => (
<f2-form>
<f2-select-field
label={'Choose a name from the list'}
documentation={"It doesn't matter who it is."}
placeholder={'Choose a name from the list'}
options={options}
{...form.connect('name')}
<f2-switch-field
label={'Enable notifications'}
documentation={
'Receive real-time updates and alerts about system events'
}
{...form.connect('notifications')}
/>
<f2-select-field
<f2-switch-field
disabled
label={'Choose a name from the list'}
label={'Maintenance mode'}
documentation={'This field is disabled'}
placeholder={'Choose a name from the list'}
options={options}
{...form.connect('name')}
{...form.connect('maintenance')}
/>
</f2-form>
);
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4372,9 +4372,9 @@ __metadata:
linkType: hard

"caniuse-lite@npm:^1.0.30001538, caniuse-lite@npm:^1.0.30001587":
version: 1.0.30001651
resolution: "caniuse-lite@npm:1.0.30001651"
checksum: fe4857b2a91a9cb77993eec9622de68bea0df17c31cb9584ca5c562f64bb3b8fda316d898aa3b1ee3ee9f7d80f6bf13c42acb09d9a56a1a6c64afaf7381472fa
version: 1.0.30001700
resolution: "caniuse-lite@npm:1.0.30001700"
checksum: 9203ed502fd1b74c47f315a001e1d91abe2abecb951f8e15dd1556cfc23a29fa7a7b2cc654380604bb6f58bcfa0c65b78055b9d99a7489c13baa0d4158a6e25e
languageName: node
linkType: hard

Expand Down

0 comments on commit 0901959

Please sign in to comment.