Skip to content

Commit

Permalink
Ui kit badge (#2189)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspergrom authored Feb 9, 2024
1 parent 91650f4 commit b35274f
Show file tree
Hide file tree
Showing 45 changed files with 197 additions and 21 deletions.
34 changes: 34 additions & 0 deletions frontend/config/styles/components/badge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:root {
/* ---------------------------------- *\
Badge sizes
\* ---------------------------------- */


/* Small */
--cr-badge-small-font-size: #{rem(12)};
--cr-badge-small-height: #{rem(22)};


/* Medium */
--cr-badge-medium-font-size: #{rem(13)};
--cr-badge-medium-height: #{rem(26)};

/* ---------------------------------- *\
Badge styles
\* ---------------------------------- */

/* Default */
--cr-badge-default-background: var(--color-gray-100);
--cr-badge-default-border: var(--color-gray-200);
--cr-badge-default-text: var(--color-gray-900);

/* White */
--cr-badge-white-background: var(--color-white);
--cr-badge-white-border: var(--color-gray-200);
--cr-badge-white-text: var(--color-gray-900);

/* Brand */
--cr-badge-brand-background: var(--color-brand-50);
--cr-badge-brand-border: var(--color-brand-100);
--cr-badge-brand-text: var(--color-brand-600);
}
1 change: 1 addition & 0 deletions frontend/config/styles/components/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "badge";
@import "button";
@import "card";
@import "checkbox";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/assets/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
@import 'form/switch';

@import '../../../config/styles';
@import '../../shared/ui-kit';
@import '../../ui-kit';
56 changes: 56 additions & 0 deletions frontend/src/ui-kit/badge/Badge.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { badgeSize } from '@/ui-kit/badge/types/BadgeSize';
import { badgeType } from '@/ui-kit/badge/types/BadgeType';
import CrBadge from './Badge.vue';

export default {
title: 'Crowd.dev/Badge',
component: CrBadge,
tags: ['autodocs'],
argTypes: {
// Props
size: {
description: 'Specifies badge size',
defaultValue: 'medium',
control: 'select',
options: badgeSize,
},
type: {
description: 'Specifies badge type',
defaultValue: 'default',
control: 'select',
options: badgeType,
},

// Slots
default: {
description: 'Text or html content of the radio',
control: {
type: null,
},
},
},
};

export const Regular = {
args: {
size: 'medium',
type: 'default',
default: 'Badge',
},
};

export const White = {
args: {
size: 'medium',
type: 'white',
default: 'Badge',
},
};

export const Brand = {
args: {
size: 'medium',
type: 'brand',
default: 'Badge',
},
};
30 changes: 30 additions & 0 deletions frontend/src/ui-kit/badge/Badge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<div
class="c-badge"
:class="[
`c-badge--${props.size}`,
`c-badge--${props.type}`,
]"
>
<slot />
</div>
</template>

<script setup lang="ts">
import { BadgeSize } from '@/ui-kit/badge/types/BadgeSize';
import { BadgeType } from '@/ui-kit/badge/types/BadgeType';
const props = withDefaults(defineProps<{
size?: BadgeSize,
type?: BadgeType,
}>(), {
size: 'medium',
type: 'default',
});
</script>

<script lang="ts">
export default {
name: 'CrBadge',
};
</script>
41 changes: 41 additions & 0 deletions frontend/src/ui-kit/badge/badge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.c-badge {
background: var(--cr-badge-background);
border: rem(1) solid var(--cr-badge-border);
color: var(--cr-badge-text);

font-size: var(--cr-badge-font-size);
height: var(--cr-badge-height);
line-height: calc(var(--cr-badge-height) - rem(2));

@apply px-2 rounded-md inline-block font-medium;

/* Badge types */
&--default{
--cr-badge-background: var(--cr-badge-default-background);
--cr-badge-border: var(--cr-badge-default-border);
--cr-badge-text: var(--cr-badge-default-text);
}

&--white{
--cr-badge-background: var(--cr-badge-white-background);
--cr-badge-border: var(--cr-badge-white-border);
--cr-badge-text: var(--cr-badge-white-text);
}

&--brand{
--cr-badge-background: var(--cr-badge-brand-background);
--cr-badge-border: var(--cr-badge-brand-border);
--cr-badge-text: var(--cr-badge-brand-text);
}

/* Badge sizes */
&--small{
--cr-badge-font-size: var(--cr-badge-small-font-size);
--cr-badge-height: var(--cr-badge-small-height);
}

&--medium{
--cr-badge-font-size: var(--cr-badge-medium-font-size);
--cr-badge-height: var(--cr-badge-medium-height);
}
}
6 changes: 6 additions & 0 deletions frontend/src/ui-kit/badge/types/BadgeSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const badgeSize = [
'small',
'medium',
] as const;

export type BadgeSize = typeof badgeSize[number];
7 changes: 7 additions & 0 deletions frontend/src/ui-kit/badge/types/BadgeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const badgeType = [
'default',
'white',
'brand',
] as const;

export type BadgeType = typeof badgeType[number];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buttonTypes } from '@/shared/ui-kit/button/types/ButtonType';
import { buttonSizes } from '@/shared/ui-kit/button/types/ButtonSize';
import { buttonNativeTypes } from '@/shared/ui-kit/button/types/ButtonNativeType';
import { buttonTypes } from '@/ui-kit/button/types/ButtonType';
import { buttonSizes } from '@/ui-kit/button/types/ButtonSize';
import { buttonNativeTypes } from '@/ui-kit/button/types/ButtonNativeType';
import CrButton from './Button.vue';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
</template>

<script setup lang="ts">
import { ButtonType } from '@/shared/ui-kit/button/types/ButtonType';
import { ButtonSize } from '@/shared/ui-kit/button/types/ButtonSize';
import { ButtonNativeType } from '@/shared/ui-kit/button/types/ButtonNativeType';
import { ButtonType } from '@/ui-kit/button/types/ButtonType';
import { ButtonSize } from '@/ui-kit/button/types/ButtonSize';
import { ButtonNativeType } from '@/ui-kit/button/types/ButtonNativeType';
const props = withDefaults(defineProps<{
type?: ButtonType,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkboxSizes } from '@/shared/ui-kit/checkbox/types/CheckboxSize';
import { checkboxSizes } from '@/ui-kit/checkbox/types/CheckboxSize';
import CrCheckbox from './Checkbox.vue';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</template>

<script setup lang="ts">
import { CheckboxSize } from '@/shared/ui-kit/checkbox/types/CheckboxSize';
import { CheckboxSize } from '@/ui-kit/checkbox/types/CheckboxSize';
import { computed, withDefaults } from 'vue';
const props = withDefaults(defineProps<{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fieldMessageTypes } from '@/shared/ui-kit/field-message/types/FieldMessageType';
import { fieldMessageTypes } from '@/ui-kit/field-message/types/FieldMessageType';
import CrFieldMessage from './FieldMessage.vue';
import CrInput from '../input/Input.vue';
import CrField from '../field/Field.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</template>

<script setup lang="ts">
import { FieldMessageType } from '@/shared/ui-kit/field-message/types/FieldMessageType';
import { FieldMessageType } from '@/ui-kit/field-message/types/FieldMessageType';
import { computed } from 'vue';
import { fieldMessageTypeData } from '@/shared/ui-kit/field-message/constants/fieldMessageTypeData';
import { fieldMessageTypeData } from '@/ui-kit/field-message/constants/fieldMessageTypeData';
const props = withDefaults(defineProps<{
type?: FieldMessageType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldMessageType } from '@/shared/ui-kit/field-message/types/FieldMessageType';
import { FieldMessageType } from '@/ui-kit/field-message/types/FieldMessageType';

interface FieldMessageTypeData{
icon: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CrField from '@/shared/ui-kit/field/Field.vue';
import CrInput from '@/shared/ui-kit/input/Input.vue';
import CrField from '@/ui-kit/field/Field.vue';
import CrInput from '@/ui-kit/input/Input.vue';
import { reactive } from 'vue';
import { email, required } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script setup lang="ts">
import { computed } from 'vue';
import CrFieldMessage from '@/shared/ui-kit/field-message/FieldMessage.vue';
import CrFieldMessage from '@/ui-kit/field-message/FieldMessage.vue';
const props = withDefaults(defineProps<{
validation: any,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'badge/badge';
@import 'button/button';
@import 'card/card';
@import 'checkbox/checkbox';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<script setup lang="ts">
import { computed, ref } from 'vue';
import CrInput from '@/shared/ui-kit/input/Input.vue';
import CrInput from '@/ui-kit/input/Input.vue';
const props = defineProps<{
modelValue: string,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { radioSizes } from '@/shared/ui-kit/radio/types/RadioSize';
import { radioSizes } from '@/ui-kit/radio/types/RadioSize';
import { reactive } from 'vue';
import CrRadio from './Radio.vue';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</template>

<script setup lang="ts">
import { RadioSize } from '@/shared/ui-kit/radio/types/RadioSize';
import { RadioSize } from '@/ui-kit/radio/types/RadioSize';
import { computed, withDefaults } from 'vue';
const props = withDefaults(defineProps<{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { switchSizes } from '@/shared/ui-kit/switch/types/SwitchSize';
import { switchSizes } from '@/ui-kit/switch/types/SwitchSize';
import CrSwitch from './Switch.vue';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</template>

<script setup lang="ts">
import { CheckboxSize } from '@/shared/ui-kit/checkbox/types/CheckboxSize';
import { CheckboxSize } from '@/ui-kit/checkbox/types/CheckboxSize';
import { computed, withDefaults } from 'vue';
const props = withDefaults(defineProps<{
Expand Down
File renamed without changes.

0 comments on commit b35274f

Please sign in to comment.