Merge pull request #117 from Safelite/CSR-241-horizontal-list-card

Csr 241 horizontal list card
This commit is contained in:
bmauger 2021-12-23 10:16:34 -05:00 committed by GitHub
commit 9bcbd90f82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 68 deletions

View file

@ -54,14 +54,15 @@
<div class="row g-2"> <div class="row g-2">
<div class="col"> <div class="col">
<fieldset> <fieldset>
<legend class="sr-only">List Card Demo</legend> <legend class="sr-only">Functioning as Checkbox</legend>
<listCard <listCard
isMultiSelect isMultiSelect
buttonImage="windshield-damage.svg" buttonImage="windshield-damage.svg"
buttonLabel="Windshield" buttonLabel="Windshield"
altText="" altText=""
buttonID="Damage Location" buttonID="List Card Checkbox"
groupID="checkbox-demo-1" groupID="checkbox-demo-1"
buttonLabelSubCopy="Description"
/> />
</fieldset> </fieldset>
</div> </div>
@ -70,13 +71,66 @@
<div class="col"> <div class="col">
<h6 class="mx-2 my-4">Functioning as Radio Button</h6> <h6 class="mx-2 my-4">Functioning as Radio Button</h6>
<fieldset> <fieldset>
<legend class="sr-only">List Card Demo</legend> <legend class="sr-only">Functioning as Radio Button</legend>
<listCard <listCard
isRadio
buttonImage="windshield-damage.svg" buttonImage="windshield-damage.svg"
buttonLabel="Windshield" buttonLabel="Windshield"
altText="" altText=""
buttonID="Damage Location Radio Button" buttonID="List Card Radio Button"
groupID="checkbox-demo-2" groupID="radio-demo-2"
buttonLabelSubCopy="Description"
/>
</fieldset>
</div>
</div>
<div class="row g-2">
<div class="col">
<h6 class="mx-2 my-4">Horizontal as Checkbox</h6>
<fieldset>
<legend class="sr-only">Horizontal Checkbox</legend>
<listCard
isMultiSelectHorizontal
buttonImage="windshield-damage.svg"
buttonLabel="Windshield"
altText=""
buttonID="List Card Horizontal Checkbox"
groupID="checkbox-demo-3"
buttonLabelSubCopy="Description"
/>
</fieldset>
</div>
</div>
<div class="row g-2">
<div class="col">
<h6 class="mx-2 my-4">Horizontal as Radio Button</h6>
<fieldset>
<legend class="sr-only">Horizontal Radio Button</legend>
<listCard
isRadioHorizontal
buttonImage="windshield-damage.svg"
buttonLabel="Windshield"
altText=""
buttonID="List Card Horizontal Radio Button"
groupID="radio-demo-4"
buttonLabelSubCopy="Description"
/>
</fieldset>
</div>
</div>
<div class="row g-2">
<div class="col">
<h6 class="mx-2 my-4">With error</h6>
<fieldset>
<legend class="sr-only">Radio button with error state</legend>
<listCard
isRadioHorizontal
buttonImage="windshield-damage.svg"
buttonLabel="Windshield"
altText=""
buttonID="Horizontal Radio Button Error State"
groupID="radio-demo-5"
buttonLabelSubCopy="Description"
/> />
</fieldset> </fieldset>
</div> </div>
@ -105,6 +159,8 @@
loaderPosition="right" loaderPosition="right"
sizeInRem="1" sizeInRem="1"
screenReaderOnlyText="(opens new window)" screenReaderOnlyText="(opens new window)"
hasError
errorMessage="Error"
/> />
<listButton <listButton
isMultiSelect isMultiSelect

View file

@ -33,13 +33,6 @@
+ p { + p {
display: none; display: none;
} }
&.error {
border: 1px solid $danger;
+ p {
display: flex;
color: $danger;
}
}
} }
} }
} }

View file

@ -115,6 +115,12 @@ $font-family-base: $font-family-sans-serif;
$font-family-code: $font-family-monospace; $font-family-code: $font-family-monospace;
$font-size-base: 1rem; // Assumes the browser default, typically `16px` $font-size-base: 1rem; // Assumes the browser default, typically `16px`
//Custom Font size (extra small)
$font-size-xsm: $font-size-base * .75;
$font-sizes: (
7: $font-size-xsm
);
//Font weight //Font weight
$font-weight-lighter: lighter; $font-weight-lighter: lighter;
$font-weight-light: 300; $font-weight-light: 300;

View file

@ -7,7 +7,6 @@
<span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span> <span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span>
<span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span> <span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span>
</label> </label>
<p class="small">{{errorMessage}}</p>
</div> </div>
<div v-else class="list-group list-button d-flex flex-column w-100 mb-2"> <div v-else class="list-group list-button d-flex flex-column w-100 mb-2">
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" @keyup.space="displayLoader()"> <input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" @keyup.space="displayLoader()">
@ -17,7 +16,6 @@
<span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span> <span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span>
<loader v-if="isLoaderDisplayed" :style="{width: `${sizeInRem}rem`, height: `${sizeInRem}rem`}" :class="[this.loaderColor, this.loaderPosition]" /> <loader v-if="isLoaderDisplayed" :style="{width: `${sizeInRem}rem`, height: `${sizeInRem}rem`}" :class="[this.loaderColor, this.loaderPosition]" />
</label> </label>
<p class="small">{{errorMessage}}</p>
</div> </div>
</template> </template>
@ -40,7 +38,6 @@ export default {
}, },
data() { data() {
return { return {
isError: false,
isLoaderDisplayed: false, isLoaderDisplayed: false,
}; };
}, },

View file

@ -1,16 +1,38 @@
<template> <template>
<div v-if="isMultiSelect" class="list-card w-100 rounded-3 d-flex align-items-center" :class="[this.invalid]"> <div v-if="isMultiSelect" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" /> <input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1"> <label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
<img v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" /> <img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
<p class="m-0 order-3">{{buttonLabel}}</p> <p class="small m-0 order-3">{{buttonLabel}}</p>
<p class="fs-7 m-0 order-4">{{buttonLabelSubCopy}}</p>
</label> </label>
</div> </div>
<div v-else class="list-card w-100 rounded-3 d-flex align-items-center" :class="[this.invalid]"> <div v-else-if="isRadio" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" /> <input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" />
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1"> <label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
<img v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" /> <img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
<p class="m-0 order-3">{{buttonLabel}}</p> <p class="small mt-2 mb-0 order-2">{{buttonLabel}}</p>
<p class="fs-7 m-0 order-3">{{buttonLabelSubCopy}}</p>
</label>
</div>
<div v-else-if="isMultiSelectHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
<div class="order-2">
<p class="m-0 small">{{buttonLabel}}</p>
<p class="m-0 fs-7">{{buttonLabelSubCopy}}</p>
</div>
</label>
</div>
<div v-else-if="isRadioHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
<input type="radio" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
<div class="order-2">
<p class="m-0 small">{{buttonLabel}}</p>
<p class="m-0 fs-7">{{buttonLabelSubCopy}}</p>
</div>
</label> </label>
</div> </div>
</template> </template>
@ -24,21 +46,28 @@ export default {
altText: String,//Leave empty. Screen readers read the buttonLabel text. If alt has content, it will repeat unnecessarily. altText: String,//Leave empty. Screen readers read the buttonLabel text. If alt has content, it will repeat unnecessarily.
buttonID: String, buttonID: String,
groupName: String, groupName: String,
isMultiSelect: Boolean isMultiSelect: Boolean,
isRadio: Boolean,
isMultiSelectHorizontal: Boolean,
isRadioHorizontal: Boolean,
buttonLabelSubCopy: String,
hasError: Boolean
} }
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
.list-card { .list-card {
&.error {
border: 1px solid $red !important;
}
border: 1px solid $gray-500; border: 1px solid $gray-500;
&.invalid { //Red border if invalid &.invalid { //Red border if invalid
border: 1px solid $red; border: 1px solid $red;
} }
img { img {
height: 46px; height: auto;
width: auto; width: 2.875rem;
order: 1;
margin-bottom: 3rem; margin-bottom: 3rem;
} }
&:hover { &:hover {
@ -51,69 +80,90 @@ export default {
position: fixed; position: fixed;
width: 0; width: 0;
+ label { + label {
display: block; display: block;
position: relative; position: relative;
&:hover { &:hover {
cursor: pointer; cursor: pointer;
} }
} }
&:focus + label { &:focus + label {
box-shadow: 0 0 0 2.5px $blue; box-shadow: 0 0 0 2.5px $blue;
border-radius: .5rem; border-radius: .5rem;
} }
&:checked + label { &:checked + label {
background: $blue-100; background: $blue-100;
box-shadow: 0 0 0 1px $blue; box-shadow: 0 0 0 1px $blue;
border-radius: .5rem; border-radius: .5rem;
} }
+ label::before { + label::before {
content: ""; content: "";
position: absolute; position: absolute;
display: flex; display: flex;
margin: 0 auto; margin: 0 auto;
width: 1rem; width: 1rem;
height: 1rem; height: 1rem;
margin: 4rem 0 0 0; margin: 3rem 0 0 0;
background: white; background: white;
border: 1px solid $gray-500; border: 1px solid $gray-500;
border-radius: 2px; border-radius: 2px;
order: 2; order: 2;
} }
&:checked + label::before { + label.checkboxTop::before {
background: $blue; margin: -1.25rem 0.5rem 0 0 !important;
} }
&:checked + label::after { + label.checkboxTop::after {
content: ''; margin: -1.5rem 0.5rem 0 0 !important;
position: absolute; }
margin: 4.2rem 0 0 0; &:checked + label::before {
border-left: 2px solid $white; background: $blue;
border-bottom: 2px solid $white; }
height: 6px; &:checked + label::after {
width: 11px; content: '';
transform: rotate(-45deg); position: absolute;
} margin: 3.2rem 0 0 0;
&:disabled + label { border-left: 2px solid $white;
color: #575757; border-bottom: 2px solid $white;
} height: 6px;
&:disabled + label::before { width: 11px;
background: #ddd; transform: rotate(-45deg);
} }
} }
input[type="radio"] { input[type="radio"] {
+ label::before { + label::before {
content: ""; content: "";
display: none; display: none;
} }
+ label::after { + label::after {
content: ""; content: "";
display: none; display: none;
} }
+ label { + label {
img { img {
height: 46px; margin-bottom: 0;
width: auto; }
}
}
&.horizontal {
img {
margin-bottom: 0;
}
input[type='checkbox'],
input[type="radio"] {
+ label::before {
content: "";
position: relative;
margin: 0 .5rem 0 0;
order: 1; order: 1;
margin-bottom: 1rem; }
&:checked + label::after {
content: '';
margin: -0.25rem 0 0 0;
left: .875rem;
}
+ label {
img {
margin-bottom: 0;
}
} }
} }
} }