Skip to content

Commit

Permalink
docs(switch & checkbox): add guidelines about readonly state
Browse files Browse the repository at this point in the history
Also
- Add guidelines for correctly labeling boolean fields
- Use better labels in the default examples of switch and checkbox
  • Loading branch information
Kiarokh committed Feb 5, 2024
1 parent 0799ddd commit 02bc3af
Show file tree
Hide file tree
Showing 15 changed files with 746 additions and 3 deletions.
1 change: 1 addition & 0 deletions guides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default [
'src/design-guidelines/disabled-hidden/disabled-hidden.md',
'src/design-guidelines/disabled-vs-readonly/disabled-vs-readonly.md',
'src/design-guidelines/boolean/switch-vs-checkbox.md',
'src/design-guidelines/boolean/labeling-boolean-fields.md',
],
},
] as Guide[];
1 change: 1 addition & 0 deletions src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { CheckboxTemplate } from './checkbox.template';
*
* @exampleComponent limel-example-checkbox
* @exampleComponent limel-example-checkbox-helper-text
* @exampleComponent limel-example-checkbox-readonly
*/
@Component({
tag: 'limel-checkbox',
Expand Down
117 changes: 117 additions & 0 deletions src/components/checkbox/examples/checkbox-readonly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Component, h, State } from '@stencil/core';
/**
* Customizing the visualization of the `readonly` state
* It is possible and recommended that you enhance the visualization of a `boolean` field
* in a `readonly` state.
*
* Because depending on the context, the default UI of the `readonly` state may not always
* provide the best way of _visualizing information_, potentially leading to
* confusion and negatively affecting the end-users' experience.
*
* :::important
* Before reading the documentations below, make sure read
* 1. our guides about the difference between
* [Disabled vs. Readonly](/#/DesignGuidelines/disabled-vs-readonly.md/) in our components.
* 2. our guidelines about [Labeling boolean fields](/#/DesignGuidelines/labeling-boolean-fields.md/).
* :::
*
* Using the readonly-related optional props of `readonlyTrueLabel`, and `readonlyFalseLabel`,
* you can override the `label` and customize it accordingly.
* Additionally, by using the `readonlyTrueIcon` and `readonlyFalseIcon` props,
* you can override the default icons and their colors.
*/
@Component({
tag: 'limel-example-checkbox-readonly',
shadow: true,
})
export class CheckboxReadonlyExample {
@State()
private readonly = true;

@State()
private value = true;

@State()
private disabled = false;

@State()
private invalid = false;

@State()
private required = false;

public render() {
return [
<limel-checkbox
disabled={this.disabled}
label="Subscribe to email newsletters"
readonlyTrueIcon="news"
readonlyFalseIcon={{
name: 'cancel_subscription',
color: 'rgb(var(--color-orange-default))',
}}
readonlyTrueLabel="Is subscribed to receive newsletters"
readonlyFalseLabel="Is unsubscribed from newsletters"
helperText={this.invalid ? 'Something is wrong' : ''}
id="1"
checked={this.value}
required={this.required}
invalid={this.invalid}
readonly={this.readonly}
/>,
<limel-example-controls>
<limel-checkbox
checked={this.readonly}
label="Readonly"
onChange={this.setReadonly}
/>
<limel-checkbox
checked={this.disabled}
label="Disabled"
onChange={this.setDisabled}
/>
<limel-checkbox
checked={this.invalid}
label="Invalid"
onChange={this.setInvalid}
/>
<limel-checkbox
checked={this.value}
label="Checked"
onChange={this.setChecked}
/>
<limel-checkbox
checked={this.required}
label="Required"
onChange={this.setRequired}
/>
</limel-example-controls>,
<limel-example-value label="Checked" value={this.value} />,
];
}

private setReadonly = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.readonly = event.detail;
};

private setChecked = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.value = event.detail;
};

private setDisabled = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.disabled = event.detail;
};

private setInvalid = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.invalid = event.detail;
};

private setRequired = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.required = event.detail;
};
}
4 changes: 2 additions & 2 deletions src/components/checkbox/examples/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class CheckboxExample {
return [
<limel-checkbox
disabled={this.disabled}
label="My fab checkbox"
id="fab"
label="Subscribe to email newsletters"
id="1"
checked={this.value}
indeterminate={this.indeterminate}
required={this.required}
Expand Down
7 changes: 7 additions & 0 deletions src/components/readonly-boolean/examples/readonly-boolean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export class ReadonlyBooleanExample {
trueLabel="You're muted"
falseLabel="Microphone is active…"
/>,
<hr></hr>,
<p>Used in Checkbox and Switch</p>,
<limel-checkbox
checked={this.value}
readonly={true}
label="Checkbox"
/>,
<limel-switch value={this.value} readonly={true} label="Switch" />,
<limel-example-controls>
<limel-checkbox
Expand Down
103 changes: 103 additions & 0 deletions src/components/switch/examples/switch-readonly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Component, h, State } from '@stencil/core';
/**
* Customizing the visualization of the `readonly` state
* It is possible and recommended that you enhance the visualization of a `boolean` field
* in a `readonly` state.
*
* Because depending on the context, the default UI of the `readonly` state may not always
* provide the best way of _visualizing information_, potentially leading to
* confusion and negatively affecting the end-users' experience.
*
* :::important
* Before reading the documentations below, make sure read
* 1. our guides about the difference between
* [Disabled vs. Readonly](/#/DesignGuidelines/disabled-vs-readonly.md/) in our components.
* 2. our guidelines about [Labeling boolean fields](/#/DesignGuidelines/labeling-boolean-fields.md/).
* :::
*
* Using the readonly-related optional props of `readonlyTrueLabel`, and `readonlyFalseLabel`,
* you can override the `label` and customize it accordingly.
* Additionally, by using the `readonlyTrueIcon` and `readonlyFalseIcon` props,
* you can override the default icons and their colors.
*/

@Component({
shadow: true,
tag: 'limel-example-switch-readonly',
})
export class SwitchReadonlyExample {
@State()
private readonly = true;

@State()
private value = true;

@State()
private disabled = false;

@State()
private invalid = false;

public render() {
return [
<limel-switch
label="Subscribe to email newsletters"
readonlyTrueIcon="news"
readonlyFalseIcon={{
name: 'cancel_subscription',
color: 'rgb(var(--color-orange-default))',
}}
readonlyTrueLabel="Is subscribed to receive newsletters"
readonlyFalseLabel="Is unsubscribed from newsletters"
helperText={this.invalid ? 'Something is wrong' : ''}
value={this.value}
disabled={this.disabled}
readonly={this.readonly}
invalid={this.invalid}
/>,
<limel-example-controls>
<limel-checkbox
checked={this.readonly}
label="Readonly"
onChange={this.setReadonly}
/>
<limel-checkbox
checked={this.disabled}
label="Disabled"
onChange={this.setDisabled}
/>
<limel-checkbox
checked={this.invalid}
label="Invalid"
onChange={this.setInvalid}
/>
<limel-checkbox
checked={this.value}
label="Selected"
onChange={this.setSelected}
/>
</limel-example-controls>,
<limel-example-value value={this.value} />,
];
}

private setReadonly = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.readonly = event.detail;
};

private setSelected = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.value = event.detail;
};

private setDisabled = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.disabled = event.detail;
};

private setInvalid = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.invalid = event.detail;
};
}
2 changes: 1 addition & 1 deletion src/components/switch/examples/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class SwitchExample {
public render() {
return [
<limel-switch
label={`Current value: ${this.value.toString()}`}
label="Bluetooth"
value={this.value}
disabled={this.disabled}
readonly={this.readonly}
Expand Down
1 change: 1 addition & 0 deletions src/components/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
*
* @exampleComponent limel-example-switch
* @exampleComponent limel-example-switch-helper-text
* @exampleComponent limel-example-switch-readonly
*/
@Component({
tag: 'limel-switch',
Expand Down
89 changes: 89 additions & 0 deletions src/design-guidelines/boolean/examples/audition-form-readonly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Component, h } from '@stencil/core';

@Component({
tag: 'limel-example-audition-form-readonly',
shadow: true,
styleUrl: 'switch-vs-checkbox.scss',
})
export class AuditionFormReadonlyExample {
public render() {
return (
<div class="do-dont-container">
<div class="do">
<limel-header
icon="ok"
heading="Example of using boolean fields in a report"
subheading="With well elaborated choices, in readonly mode"
/>
<div class="container">
<h4>Gender inclusive workplace audition summary</h4>
<p>
The audited company have taken proper measures to…
</p>
<limel-checkbox
readonly={true}
checked={true}
label="Respect and call staff by their choice of pronouns"
/>
<limel-checkbox
readonly={true}
label="Allow any dress codes that represent their gender identity"
/>
<limel-checkbox
readonly={true}
checked={true}
label="Have gender-neutral toilets"
/>
<limel-checkbox
readonly={true}
checked={true}
label="Stop gender discrimination in the recruitment"
/>
<limel-checkbox
readonly={true}
label="Have a protocol for sexual harassment in workplace"
/>
<p> ···</p>
</div>
</div>
<div class="do-not">
<limel-header
icon="brake_warning"
heading="Example of using boolean fields in a report"
subheading="Same form but with abstract choices, in readonly mode"
/>
<div class="container">
<h4>Gender inclusive workplace audition summary</h4>
<p>
The audited company have taken proper measures to…
</p>
<limel-checkbox
readonly={true}
checked={true}
label="Normalize sharing of pronouns"
/>
<limel-checkbox
readonly={true}
label="Dress codes that represent gender identity"
/>
<limel-checkbox
readonly={true}
checked={true}
label="Gender-neutral toilets"
/>
<limel-checkbox
readonly={true}
checked={true}
label="Discrimination in the recruitment"
/>
<limel-checkbox
readonly={true}
label="Protocol for sexual harassment"
/>
<p> ···</p>
</div>
</div>
</div>
);
}
}
Loading

0 comments on commit 02bc3af

Please sign in to comment.