Skip to content

Commit

Permalink
fixup! feat(dynamic-label): add new component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiarokh committed Apr 2, 2024
1 parent 40dc62e commit a36c86a
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 91 deletions.
1 change: 1 addition & 0 deletions src/components/dynamic-label/dynamic-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Icon } from '../../interface';
* confusion and negatively affecting the end-users' experience.
*
* @exampleComponent limel-example-dynamic-label
* @exampleComponent limel-example-dynamic-label-readonly-boolean
* @beta
*/
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:host(limel-example-dynamic-label) {
:host(limel-example-dynamic-label-readonly-boolean) {
--example-controls-column-layout: auto-fit;
display: grid;
gap: 1rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { Component, State, h } from '@stencil/core';

/**
* Readonly boolean
* The `readonly` mode of a boolean fields do not always
* clearly communicate the meaning of the data to the end users. Similar problems
* have existed in user interfaces forever, and it not solely limited to
* readonly-ness of a boolean field. If you are interested in reading more
* about these common design problems, you can check out
* [**State-Switch Controls:** The Infamous Case of the "Mute" Button](https://www.nngroup.com/articles/state-switch-buttons/)
*
* In short, the reason end-users become confused is that it is not enough to
* keep the same label for both `true` and `false` states,
* and only rely on changing the color or the
* shapes and visual motifs, to communicate what the field means.
*
* Instead, we need to use different labels to describe the state,
* and also get some additional help from icons and colors
* to clarify further if needed.
*
* :::important
* This example shows how to setup the `limel-dynamic-label` component to
* create a more descriptive and dynamic labels for boolean fields.
* But please make sure to read our guidelines about
* [Labeling boolean fields](/#/DesignGuidelines/labeling-boolean-fields.md/)
* to understand the importance of this, and get help in choosing the right labels
* for boolean fields.
* :::
*/
@Component({
tag: 'limel-example-dynamic-label-readonly-boolean',
shadow: true,
styleUrl: 'dynamic-label-readonly-boolean.scss',
})
export class DynamicLabelExample {
@State()
private value: boolean = false;

public render() {
return [
<p>Default</p>,
<limel-dynamic-label
defaultLabel={{ text: 'Debt', icon: 'minus' }}
/>,
<hr></hr>,
<p>Customized</p>,
<limel-dynamic-label
defaultLabel={{ text: 'Debt' }}
value={this.value}
labels={[
{
value: true,
text: 'Has debts',
icon: {
name: 'error',
color: 'rgb(var(--color-red-default))',
backgroundColor: 'rgb(var(--color-yellow-default))',
},
},
{
value: false,
text: 'Does not have debts',
icon: {
name: 'ok',
color: 'rgb(var(--color-green-default))',
},
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Newsletter' }}
value={this.value}
labels={[
{
value: true,
icon: 'news',
text: 'Subscribed to receive newsletters',
},
{
value: false,
icon: {
name: 'cancel_subscription',
color: 'rgb(var(--color-orange-default))',
},
text: 'Unsubscribed from newsletters',
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Quit' }}
value={this.value}
labels={[
{
value: true,
icon: {
name: 'inactive_state',
color: 'rgb(var(--color-gray-default))',
},
text: 'Has quit their job',
},
{
value: false,
icon: {
name: 'in_progress',
color: 'rgb(var(--color-sky-default))',
},
text: 'Still works here',
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Mute' }}
value={this.value}
labels={[
{
value: true,
icon: {
name: 'no_microphone',
color: 'rgb(var(--color-gray-light))',
},
text: "You're muted",
},
{
value: false,
icon: 'microphone',
text: '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
checked={this.value}
label="Value"
onChange={this.setChecked}
/>
<limel-example-value label="Current value" value={this.value} />
</limel-example-controls>,
];
}

private setChecked = (event: CustomEvent<boolean>) => {
event.stopPropagation();
this.value = event.detail;
};
}
93 changes: 3 additions & 90 deletions src/components/dynamic-label/examples/dynamic-label.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
import { Component, State, h } from '@stencil/core';

/**
* Readonly boolean
* The `readonly` mode of a boolean fields do not always
* clearly communicate the meaning of the data to the end users. Similar problems
* have existed in user interfaces forever, and it not solely limited to
* readonly-ness of a boolean field. If you are interested in reading more
* about these common design problems, you can check out
* [**State-Switch Controls:** The Infamous Case of the "Mute" Button](https://www.nngroup.com/articles/state-switch-buttons/)
* Basic example
*
* In short, the reason end-users become confused is that it is not enough to
* keep the same label for both `true` and `false` states,
* and only rely on changing the color or the
* shapes and visual motifs, to communicate what the field means.
*
* Instead, we need to use different labels to describe the state,
* and also get some additional help from icons and colors
* to clarify further if needed.
* Switching the value to `true` or `false` will dynamically change the label,
* while the default label (including its icon) is ignored.
*/
@Component({
tag: 'limel-example-dynamic-label',
shadow: true,
styleUrl: 'dynamic-label.scss',
})
export class DynamicLabelExample {
@State()
private value: boolean = false;

public render() {
return [
<p>Default</p>,
<limel-dynamic-label
defaultLabel={{ text: 'Debt', icon: 'minus' }}
/>,
<hr></hr>,
<p>Customized</p>,
<limel-dynamic-label
defaultLabel={{ text: 'Debt' }}
value={this.value}
labels={[
{
Expand All @@ -58,74 +39,6 @@ export class DynamicLabelExample {
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Newsletter' }}
value={this.value}
labels={[
{
value: true,
icon: 'news',
text: 'Subscribed to receive newsletters',
},
{
value: false,
icon: {
name: 'cancel_subscription',
color: 'rgb(var(--color-orange-default))',
},
text: 'Unsubscribed from newsletters',
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Quit' }}
value={this.value}
labels={[
{
value: true,
icon: {
name: 'inactive_state',
color: 'rgb(var(--color-gray-default))',
},
text: 'Has quit their job',
},
{
value: false,
icon: {
name: 'in_progress',
color: 'rgb(var(--color-sky-default))',
},
text: 'Still works here',
},
]}
/>,
<limel-dynamic-label
defaultLabel={{ text: 'Mute' }}
value={this.value}
labels={[
{
value: true,
icon: {
name: 'no_microphone',
color: 'rgb(var(--color-gray-light))',
},
text: "You're muted",
},
{
value: false,
icon: 'microphone',
text: '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
checked={this.value}
Expand Down

0 comments on commit a36c86a

Please sign in to comment.