Skip to content

Commit

Permalink
fix(useVariant): allow custom variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjoertjuh committed Nov 22, 2023
1 parent 547bd9d commit 643ad64
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
3 changes: 1 addition & 2 deletions src/composables/useVariant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useStringTemplate from '@/composables/useStringTemplate';

export const variants = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'link'] as const;

export type Variant = typeof variants[number];
export type Variant = typeof variants[number] | string;

export default (variant: MaybeRef<Variant>, classTemplate: MaybeRef<string>) => {
const {templatedString} = useStringTemplate(classTemplate, variant);
Expand All @@ -15,7 +15,6 @@ export const variantProp = (defaultValue: Variant | '' | undefined = 'primary')
return {
type: String as PropType<Variant>,
default: defaultValue,
validator: (v?: Variant) => v ? variants.includes(v) : true,
};
};

Expand Down
24 changes: 0 additions & 24 deletions src/composables/useVariant/useVariant.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import useVariant, {variantProp, variantProps, variants} from '.';

Check failure on line 1 in src/composables/useVariant/useVariant.test.ts

View workflow job for this annotation

GitHub Actions / test

'variantProps' is defined but never used

Check warning on line 1 in src/composables/useVariant/useVariant.test.ts

View workflow job for this annotation

GitHub Actions / test

'variantProps' is defined but never used

Check failure on line 1 in src/composables/useVariant/useVariant.test.ts

View workflow job for this annotation

GitHub Actions / test

'variants' is defined but never used

Check warning on line 1 in src/composables/useVariant/useVariant.test.ts

View workflow job for this annotation

GitHub Actions / test

'variants' is defined but never used

describe('variantProps', () => {
describe('variant', () => {
variants.forEach((s) => {
it(`passes validation with ${s}`, () => {
const result = variantProps.variant.validator(s);

expect(result).toBe(true);
});
});

it('passes validation with empty value', () => {
const result = variantProps.variant.validator(undefined);

expect(result).toBe(true);
});

it('passes validation with a non variant', () => {
const result = variantProps.variant.validator('non-variant');

expect(result).toBe(false);
});
});
});

describe('variantProp', () => {
it('sets the default value', () => {
const prop = variantProp('');
Expand Down

0 comments on commit 643ad64

Please sign in to comment.