Skip to content

Commit

Permalink
Tracker: improve CheckBox (#1356)
Browse files Browse the repository at this point in the history
Signed-off-by: Artyom Grigorovich <grigorovichartyom@gmail.com>
  • Loading branch information
agrigorovich-xored authored Apr 12, 2022
1 parent fd92ec7 commit b3d6a11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
14 changes: 13 additions & 1 deletion packages/ui/src/components/CheckBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@
// limitations under the License.
-->
<script lang="ts">
import { createEventDispatcher } from 'svelte'
export let checked: boolean = false
export let symbol: 'check' | 'minus' = 'check'
export let circle: boolean = false
export let primary: boolean = false
const dispatch = createEventDispatcher()
const handleValueChanged = (event: Event) => {
const eventTarget = event.target as HTMLInputElement
const isChecked = eventTarget.checked
dispatch('value', isChecked)
}
</script>

<label class="checkbox" class:circle class:primary class:checked>
<input class="chBox" type="checkbox" bind:checked on:change />
<input class="chBox" type="checkbox" bind:checked on:change={handleValueChanged} />
<svg class="checkSVG" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
{#if !circle}
<path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@
})
}
const handleIssueSelected = (id: Ref<Doc>, event: Event) => {
const eventTarget = event.target as HTMLInputElement
const isChecked = eventTarget.checked
if (isChecked) {
const handleIssueSelected = (id: Ref<Doc>, event: CustomEvent<boolean>) => {
if (event.detail) {
selectedIssueIds.add(id)
} else {
selectedIssueIds.delete(id)
Expand Down Expand Up @@ -116,7 +113,7 @@
<div class="eListGridCheckBox ml-2">
<CheckBox
checked={selectedIssueIds.has(docObject._id)}
on:change={(event) => {
on:value={(event) => {
handleIssueSelected(docObject._id, event)
}}
/>
Expand Down
36 changes: 20 additions & 16 deletions plugins/view-resources/src/components/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
const dispatch = createEventDispatcher()
$: sortingFunction = (config.find(it => (typeof it !== 'string') && it.sortingKey === sortKey) as BuildModelKey)?.sortingFunction
$: sortingFunction = (config.find((it) => typeof it !== 'string' && it.sortingKey === sortKey) as BuildModelKey)
?.sortingFunction
let qindex = 0
async function update (
Expand Down Expand Up @@ -103,11 +104,9 @@
let checked: Set<Ref<Doc>> = new Set<Ref<Doc>>()
function check (id: Ref<Doc>, e: Event) {
function check (id: Ref<Doc>, event: CustomEvent<boolean>) {
if (!enableChecking) return
const target = e.target as HTMLInputElement
const value = target.checked
if (value) {
if (event.detail) {
checked.add(id)
} else {
checked.delete(id)
Expand Down Expand Up @@ -138,8 +137,8 @@
<CheckBox
symbol={'minus'}
checked={objects?.length === checked.size && objects?.length > 0}
on:change={(e) => {
objects.map((o) => check(o._id, e))
on:value={(event) => {
objects.map((object) => check(object._id, event))
}}
/>
</div>
Expand Down Expand Up @@ -182,20 +181,23 @@
<div class="antiTable-cells__checkCell">
<CheckBox
checked={checked.has(object._id)}
on:change={(e) => {
check(object._id, e)
on:value={(event) => {
check(object._id, event)
}}
/>
</div>
{/if}
<Component is={notification.component.NotificationPresenter} props={{ value: object, kind: enableChecking ? 'table' : 'block' }} />
<Component
is={notification.component.NotificationPresenter}
props={{ value: object, kind: enableChecking ? 'table' : 'block' }}
/>
</div>
{:else}
<div class="antiTable-cells__checkCell">
<CheckBox
checked={checked.has(object._id)}
on:change={(e) => {
check(object._id, e)
on:value={(event) => {
check(object._id, event)
}}
/>
</div>
Expand All @@ -209,7 +211,11 @@
value={getObjectValue(attribute.key, object) ?? ''}
{...attribute.props}
/>
<div id='context-menu' class="antiTable-cells__firstCell-menuRow" on:click={(ev) => showMenu(ev, object, row)}>
<div
id="context-menu"
class="antiTable-cells__firstCell-menuRow"
on:click={(ev) => showMenu(ev, object, row)}
>
<MoreV size={'small'} />
</div>
</div>
Expand All @@ -236,9 +242,7 @@
{#if enableChecking}
<td>
<div class="antiTable-cells__checkCell">
<CheckBox
checked={false}
/>
<CheckBox checked={false} />
</div>
</td>
{/if}
Expand Down

0 comments on commit b3d6a11

Please sign in to comment.