Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component/choice #27

Merged
merged 22 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b5f5779
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 8, 2021
bb21e58
Update: add Choice component
HQCuong Dec 8, 2021
f1d7b6b
Fix: modify helpText slot in Choice component
HQCuong Dec 8, 2021
32f9551
Fix: modify label property in Choice component
HQCuong Dec 8, 2021
0c5405a
Fix: change className computed to wrapperClassName in Choice component
HQCuong Dec 9, 2021
3886345
Fix: use uppercase for helpTextID computed (old helpTextId)
HQCuong Dec 9, 2021
c183fe0
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 9, 2021
a05838b
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 10, 2021
a15229b
Fix: modify type for error prop and change computed name childrenClas…
HQCuong Dec 10, 2021
ac739b0
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 13, 2021
42b9e30
Update: export helpTextId in Choice component
HQCuong Dec 13, 2021
b8fcecb
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 14, 2021
783a7df
Fix: modify spelling mistake fieldId to fieldID in template
HQCuong Dec 14, 2021
a959b1c
Merge remote-tracking branch 'origin/component/inline-error' into com…
HQCuong Dec 16, 2021
1447344
Update: add type array, function for error prop
HQCuong Dec 16, 2021
4a167a8
Fix: using import type instead of import
HQCuong Dec 17, 2021
09fd90b
Merge remote-tracking branch 'origin/dev' into component/choice
HQCuong Dec 21, 2021
1309a39
Merge remote-tracking branch 'origin/dev' into component/choice
HQCuong Dec 28, 2021
35048b7
Merge remote-tracking branch 'origin/dev' into component/choice
HQCuong Dec 29, 2021
53940b9
Update: modify part of Error type in Choice Component
HQCuong Dec 29, 2021
a0c948b
Fix: remove unnecessary label prop
HQCuong Dec 29, 2021
deb3865
Fix: remove unnecessary space char in label slot
HQCuong Dec 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';