This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
forked from ONSvisual/census-atlas
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ONSdigital/feature/design-system-checkboxes
Feature/design system checkboxes - ticket#85
- Loading branch information
Showing
4 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
<div class="ons-input-items"> | ||
<p class="ons-checkboxes__label">Select all that apply</p> | ||
<div class="ons-checkboxes__items"> | ||
<slot /> | ||
<script> | ||
import { setContext } from "svelte"; | ||
import ONSError from "./partials/ONSError.svelte"; | ||
export let checkboxesLabel, title, id, name, renderError; | ||
setContext("name", name); | ||
export let legendIsQuestionTitle = false; | ||
export let errorText = "Select [whatever it is]"; | ||
</script> | ||
|
||
<ONSError {errorText} id={name} {renderError}> | ||
<div class="ons-question ons-u-mt-no"> | ||
<fieldset {id} class="ons-fieldset"> | ||
{#if legendIsQuestionTitle} | ||
<legend class="ons-fieldset__legend"> | ||
<h1 id="{id}-legend-title" class="ons-fieldset__legend-title ">{title}</h1> | ||
</legend> | ||
{/if} | ||
<div class="ons-input-items"> | ||
<p class="ons-checkboxes__label">{checkboxesLabel}</p> | ||
<div class="ons-checkboxes__items"> | ||
<slot /> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> | ||
</div> | ||
</ONSError> |
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 |
---|---|---|
@@ -1,12 +1,34 @@ | ||
<script> | ||
export let id; | ||
export let value; | ||
export let checked = false; | ||
import { getContext } from "svelte"; | ||
export let id, value, labelText, onChange; | ||
let name = getContext("name"); | ||
export let bindGroup = []; | ||
function onChangeBindGroup({ target }) { | ||
const { value, checked } = target; | ||
if (checked) { | ||
bindGroup = [...bindGroup, value]; | ||
} else { | ||
bindGroup = bindGroup.filter((item) => item !== value); | ||
} | ||
} | ||
</script> | ||
|
||
<p class="ons-checkboxes__item"> | ||
<span class="ons-checkboxes__item"> | ||
<span class="ons-checkbox "> | ||
<input type="checkbox" {id} class="ons-checkbox__input ons-js-checkbox " bind:checked /> | ||
<label class="ons-checkbox__label" for={id} id="{id}-label"><slot /></label> | ||
<input | ||
type="checkbox" | ||
{id} | ||
class="ons-checkbox__input ons-js-checkbox " | ||
{value} | ||
{name} | ||
checked={bindGroup.includes(value)} | ||
on:change={(e) => { | ||
onChangeBindGroup(e); | ||
onChange(bindGroup); | ||
}} | ||
/> | ||
<label class="ons-checkbox__label " for={id} id="{id}-label">{labelText} </label> | ||
</span> | ||
</p> | ||
</span> | ||
<br /> |