Skip to content

Commit

Permalink
Merge pull request #27 from qikify/component/choice
Browse files Browse the repository at this point in the history
Component/choice
  • Loading branch information
juzser authored Dec 30, 2021
2 parents bc4587e + deb3865 commit d28f2cb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/classes/Choice.json
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"}
89 changes: 89 additions & 0 deletions src/components/Choice/Choice.vue
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>
1 change: 1 addition & 0 deletions src/components/Choice/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Choice } from './Choice.vue';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './UnstyledLink';
export * from './Icon';
export * from './VisuallyHidden';
export * from './InlineError';
export * from './Choice';

0 comments on commit d28f2cb

Please sign in to comment.