Skip to content

Commit

Permalink
feat(checkbox): add indeterminate state
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kopco authored and nowseemee committed Jul 19, 2021
1 parent 0d1eab1 commit 0a895c4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
5 changes: 4 additions & 1 deletion packages/components/src/components/checkbox/checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ scale-checkbox {
display: flex;
flex-wrap: wrap;
align-items: center;
cursor: pointer;
}

.checkbox .checkbox__control-wrapper {
Expand All @@ -67,19 +68,21 @@ scale-checkbox {
display: flex;
position: relative;
align-items: center;
margin-right: var(--spacing-x);
}

.checkbox__label-wrapper {
display: flex;
flex-wrap: wrap;
align-items: center;
cursor: pointer;
gap: var(--spacing-x);
}

.checkbox .checkbox__label {
color: var(--color-text);
font-weight: var(--font-weight-label);
transition: var(--transition-label);
cursor: pointer;
}

.checkbox .checkbox__meta {
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class Checkbox {
name={this.name}
id={this.inputId}
onChange={(e: any) => {
if(this.indeterminate) this.indeterminate = false
this.checked = e.target.checked;
// bubble event through the shadow dom
this.scaleChange.emit({ value: this.checked });
Expand All @@ -86,14 +87,14 @@ export class Checkbox {
<div class="checkbox__control-wrapper">
<span class="checkbox__control"></span>
{/* Accessibility: rendering the icon *only* when checked, otherwise is always visible in HCM */}
{this.checked && (
{this.checked && !this.indeterminate && (
<scale-icon-action-success
class="checkbox__icon"
decorative
></scale-icon-action-success>
)}
{this.indeterminate && (
<scale-icon-action-play class="checkbox__icon"></scale-icon-action-play>
<scale-icon-action-indeterminate class="checkbox__icon"></scale-icon-action-indeterminate>
)}
</div>
<span class="checkbox__label">
Expand Down
30 changes: 14 additions & 16 deletions packages/components/src/components/checkbox/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ---------------- | ---------------- | ------------------------------ | ------------------ | ----------- |
| `checked` | `checked` | (optional) Active switch | `boolean` | `false` |
| `disabled` | `disabled` | (optional) Input disabled | `boolean` | `undefined` |
| `helperText` | `helper-text` | (optional) Input helper text | `string` | `''` |
| `indeterminated` | `indeterminated` | (optional) indeterminated | `boolean` | `false` |
| `inputId` | `input-id` | (optional) Input checkbox id | `string` | `undefined` |
| `label` | `label` | (optional) Input label | `string` | `''` |
| `name` | `name` | (optional) Input name | `string` | `''` |
| `status` | `status` | (optional) Input status | `string` | `''` |
| `styles` | `styles` | (optional) Injected CSS styles | `string` | `undefined` |
| `value` | `value` | (optional) Input value | `number \| string` | `''` |
| Property | Attribute | Description | Type | Default |
| --------------- | --------------- | ------------------------------ | ------------------ | ----------- |
| `checked` | `checked` | (optional) Active switch | `boolean` | `false` |
| `disabled` | `disabled` | (optional) Input disabled | `boolean` | `undefined` |
| `helperText` | `helper-text` | (optional) Input helper text | `string` | `''` |
| `indeterminate` | `indeterminate` | (optional) indeterminate | `boolean` | `false` |
| `inputId` | `input-id` | (optional) Input checkbox id | `string` | `undefined` |
| `label` | `label` | (optional) Input label | `string` | `''` |
| `name` | `name` | (optional) Input name | `string` | `''` |
| `status` | `status` | (optional) Input status | `string` | `''` |
| `styles` | `styles` | (optional) Injected CSS styles | `string` | `undefined` |
| `value` | `value` | (optional) Input value | `number \| string` | `''` |


## Events
Expand All @@ -32,20 +32,18 @@

### Used by

- [scale-checkbox-group](../checkbox-group)
- [scale-data-grid](../data-grid)

### Depends on

- [scale-icon-action-success](../icons/action-success)
- [scale-icon-action-play](../icons/action-play)
- [scale-icon-action-indeterminate](../icons/action-indeterminate)

### Graph
```mermaid
graph TD;
scale-checkbox --> scale-icon-action-success
scale-checkbox --> scale-icon-action-play
scale-checkbox-group --> scale-checkbox
scale-checkbox --> scale-icon-action-indeterminate
scale-data-grid --> scale-checkbox
style scale-checkbox fill:#f9f,stroke:#333,stroke-width:4px
```
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/data-grid/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ graph TD;
scale-menu-flyout-item --> scale-icon-action-success
scale-menu-flyout-item --> scale-icon-navigation-right
scale-checkbox --> scale-icon-action-success
scale-checkbox --> scale-icon-action-indeterminate
scale-dropdown --> scale-icon-navigation-collapse-down
scale-tag --> scale-icon-action-close
style scale-data-grid fill:#f9f,stroke:#333,stroke-width:4px
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a895c4

Please sign in to comment.