-
Notifications
You must be signed in to change notification settings - Fork 29
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 #27 from qikify/component/choice
Component/choice
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Choice":"Polaris-Choice","labelHidden":"Polaris-Choice--labelHidden","Label":"Polaris-Choice__Label","Control":"Polaris-Choice__Control","disabled":"Polaris-Choice--disabled","Descriptions":"Polaris-Choice__Descriptions","HelpText":"Polaris-Choice__HelpText"} |
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,89 @@ | ||
<template lang="pug"> | ||
div | ||
label(:class="wrapperClassName", :for="id") | ||
span(:class="controlClass") | ||
slot | ||
span(:class="labelClass") | ||
slot(name="label") | ||
div( | ||
v-if="error || $slots.helpText", | ||
:class="descriptionMarkupClass", | ||
) | ||
div( | ||
v-if="$slots.helpText", | ||
:id="helpTextID", | ||
:class="helpTextClass", | ||
) | ||
slot(name="helpText") | ||
InlineError( | ||
v-if="(error && typeof error !== 'boolean')", | ||
:fieldID="id", | ||
:message="error", | ||
) | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
import { Component, Prop } from 'vue-property-decorator'; | ||
import { classNames } from 'polaris-react/src/utilities/css'; | ||
import type { Error } from 'types/type'; | ||
import styles from '@/classes/Choice.json'; | ||
import { InlineError } from '../InlineError'; | ||
export const helpTextID = (id: string): string => `${id}HelpText`; | ||
@Component({ | ||
components: { | ||
InlineError, | ||
}, | ||
}) | ||
export default class Choice extends Vue { | ||
/** | ||
* A unique identifier for the choice | ||
*/ | ||
@Prop({ type: String, required: true }) | ||
public id!: string; | ||
/** | ||
* Whether the associated form control is disabled | ||
*/ | ||
@Prop({ type: Boolean }) | ||
public disabled!: boolean; | ||
/** | ||
* Display an error message | ||
*/ | ||
@Prop({ type: [String, Array, Object, Function, Boolean] }) | ||
public error!: Error | boolean; | ||
/** | ||
* Visually hide the label | ||
*/ | ||
@Prop({ type: Boolean }) | ||
public labelHidden!: boolean; | ||
public controlClass: string = styles.Control; | ||
public labelClass: string = styles.Label; | ||
public descriptionMarkupClass: string = styles.Descriptions; | ||
public helpTextClass: string = styles.HelpText; | ||
get wrapperClassName(): string { | ||
return classNames( | ||
styles.Choice, | ||
this.labelHidden && styles.labelHidden, | ||
this.disabled && styles.disabled, | ||
); | ||
} | ||
get helpTextID(): string { | ||
return helpTextID(this.id); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
@import 'polaris-react/src/components/Choice/Choice.scss'; | ||
</style> |
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 @@ | ||
export { default as Choice } from './Choice.vue'; |
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