-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
20 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/components/src/components/checkbox-group/checkbox-group.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.checkbox-group { | ||
display: inline-flex; | ||
flex-direction: column; | ||
width: 300px; | ||
} | ||
|
||
.checkbox-group__container { | ||
display: flex; | ||
flex-direction: column; | ||
margin-left: 1.5rem; | ||
} | ||
|
||
.checkbox-group__checkbox { | ||
margin-top: 0.5rem; | ||
} |
110 changes: 110 additions & 0 deletions
110
packages/components/src/components/checkbox-group/checkbox-group.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* @license | ||
* Scale https://github.com/telekom/scale | ||
* | ||
* Copyright (c) 2021 Egor Kirpichev and contributors, Deutsche Telekom AG | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Component, h, Host, Listen, Element } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'scale-checkbox-group', | ||
styleUrl: './checkbox-group.css', | ||
shadow: true, | ||
}) | ||
export class CheckboxGroup { | ||
@Element() hostElement: HTMLElement; | ||
@Listen('scaleChange') | ||
scaleChangeHandler(event: CustomEvent<any>) { | ||
console.log('Received the scaleChange event: ', event.detail); | ||
this.setCheckboxes(event); | ||
} | ||
|
||
connectedCallback() { | ||
this.setCheckboxes = this.setCheckboxes.bind(this); | ||
} | ||
|
||
setCheckboxes(event: CustomEvent<any>) { | ||
const checkboxes = Array.from( | ||
this.hostElement.shadowRoot.querySelectorAll('scale-checkbox') | ||
); | ||
const checked = event.detail.checked; | ||
let countChecked = 0; | ||
let countUnchecked = 0; | ||
if (event.detail.id === 'checkbox1') { | ||
checkboxes.forEach((checkbox) => { | ||
checkbox.checked = checked; | ||
}); | ||
} else { | ||
for (let i = 1; i < checkboxes.length; i++) { | ||
if (checkboxes[i].checked) { | ||
countChecked = countChecked + 1; | ||
} else { | ||
countUnchecked = countUnchecked + 1; | ||
} | ||
} | ||
} | ||
|
||
if (countChecked === checkboxes.length - 1) { | ||
checkboxes[0].checked = true; | ||
return; | ||
} | ||
if (countUnchecked === checkboxes.length - 1) { | ||
checkboxes[0].checked = false; | ||
return; | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<div class="checkbox-group"> | ||
<div class="checkbox-group__label"> | ||
<scale-checkbox | ||
input-id="checkbox1" | ||
value="1" | ||
label="checkbox" | ||
name="nameOfCheckbox" | ||
helper-text="helperText" | ||
checked | ||
></scale-checkbox> | ||
</div> | ||
<div class="checkbox-group__container"> | ||
<div class="checkbox-group__checkbox"> | ||
<scale-checkbox | ||
input-id="checkbox2" | ||
value="2" | ||
label="checkbox" | ||
name="nameOfCheckbox" | ||
></scale-checkbox> | ||
</div> | ||
<div class="checkbox-group__checkbox"> | ||
<scale-checkbox | ||
input-id="checkbox3" | ||
value="3" | ||
label="checkbox" | ||
name="nameOfCheckbox" | ||
></scale-checkbox> | ||
</div> | ||
<div class="checkbox-group__checkbox"> | ||
<scale-checkbox | ||
input-id="checkbox4" | ||
value="4" | ||
label="checkbox" | ||
name="nameOfCheckbox" | ||
checked | ||
></scale-checkbox> | ||
</div> | ||
</div> | ||
</div> | ||
{/* <button class="button" onClick={this.setCheckboxes}> | ||
click | ||
</button>*/} | ||
</Host> | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/components/src/components/checkbox-group/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# scale-checkbox-group | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Dependencies | ||
|
||
### Depends on | ||
|
||
- [scale-checkbox](../checkbox) | ||
|
||
### Graph | ||
```mermaid | ||
graph TD; | ||
scale-checkbox-group --> scale-checkbox | ||
scale-checkbox --> scale-icon-action-success | ||
scale-checkbox --> scale-icon-action-play | ||
style scale-checkbox-group fill:#f9f,stroke:#333,stroke-width:4px | ||
``` | ||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters