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

Ui kit checkbox #2159

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
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 frontend/.storybook/storybook.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import 'https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css';
@import 'https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap';

// fixing storybook broken styles because of imported styles
.tag{
4 changes: 4 additions & 0 deletions frontend/config/styles/components/card.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
:root {
/* ---------------------------------- *\
Card style
\* ---------------------------------- */

--cr-card-shadow: var(--shadow-default);
--cr-card-radius: #{rem(8)};
--cr-card-background: var(--color-white);
54 changes: 54 additions & 0 deletions frontend/config/styles/components/checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
:root {
/* ---------------------------------- *\
Checkbox style
\* ---------------------------------- */

// General style
--cr-checkbox-shadow: var(--shadow-s);
--cr-checkbox-border-radius: #{rem(4)};

// Text style
--cr-checkbox-text-font-weight: var(--font-medium);
--cr-checkbox-text-color: var(--color-gray-900);

// Description style
--cr-checkbox-description-font-size: #{rem(12)};
--cr-checkbox-description-line-height: #{rem(15)};
--cr-checkbox-description-font-weight: var(--font-normal);
--cr-checkbox-description-color: var(--color-gray-500);
--cr-checkbox-description-spacing: #{rem(4)};

// Unchecked
--cr-checkbox-unchecked-border: var(--color-gray-300);
--cr-checkbox-unchecked-background: var(--color-white);
--cr-checkbox-unchecked-icon: var(--color-white);

// Checked
--cr-checkbox-checked-border: var(--color-gray-900);
--cr-checkbox-checked-background: var(--color-gray-900);
--cr-checkbox-checked-icon: var(--color-white);

// Disabled Unchecked
--cr-checkbox-disabled-unchecked-border: var(--color-gray-200);
--cr-checkbox-disabled-unchecked-background: var(--color-white);
--cr-checkbox-disabled-unchecked-icon: var(--color-white);

// Disabled Checked
--cr-checkbox-disabled-checked-border: var(--color-gray-400);
--cr-checkbox-disabled-checked-background: var(--color-gray-400);
--cr-checkbox-disabled-checked-icon: var(--color-white);

/* ---------------------------------- *\
Checkbox sizes
\* ---------------------------------- */

/* Small */
--cr-checkbox-small-size: #{rem(14)};
--cr-checkbox-small-font-size: #{rem(13)};
--cr-checkbox-small-line-height: 1.25;

/* Medium */
--cr-checkbox-medium-size: #{rem(16)};
--cr-checkbox-medium-font-size: #{rem(14)};
--cr-checkbox-medium-line-height: 1.25;
}
1 change: 1 addition & 0 deletions frontend/config/styles/components/index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "button";
@import "card";
@import "checkbox";
10 changes: 10 additions & 0 deletions frontend/config/styles/variables/_font.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* ---------------------------------- *\
Font
\* ---------------------------------- */

:root {
--font-light: 300;
--font-normal: 400;
--font-medium: 500;
--font-bold: 700;
}
1 change: 1 addition & 0 deletions frontend/config/styles/variables/index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "colors";
@import "font";
@import "shadows";
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@
"test:e2e:run": "npx cypress run --headed --browser chrome",
"test:e2e:staging:open": "npx cypress open --config-file cypress.staging.config.js",
"test:e2e:staging:run": "npx cypress run --config-file cypress.staging.config.js",
"tailwind:view": "tailwind-config-viewer -o",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"docs:tailwind": "tailwind-config-viewer -o",
"docs:storybook": "storybook dev -p 6006",
"docs:storybook:build": "storybook build",
"docs": "npm run docs:tailwind & npm run docs:storybook"
},
"dependencies": {
"@cubejs-client/core": "^0.31.63",
65 changes: 65 additions & 0 deletions frontend/src/shared/ui-kit/checkbox/Checkbox.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { checkboxSizes } from '@/shared/ui-kit/checkbox/types/CheckboxSize';
import CrCheckbox from './Checkbox.vue';

export default {
title: 'Crowd.dev/Checkbox',
component: CrCheckbox,
tags: ['autodocs'],
argTypes: {
// Props
size: {
description: 'Specifies checkbox size',
defaultValue: 'medium',
control: 'select',
options: checkboxSizes,
},
modelValue: {
description: 'Checkbox value',
control: {
type: null,
},
},
value: {
description: 'Value for checkbox when checked',
control: {
type: null,
},
},
disabled: {
description: 'Specifies if checkbox is disabled',
defaultValue: false,
control: 'boolean',
},
multiple: {
description: 'Specifies if checkbox is disabled',
defaultValue: false,
control: 'boolean',
},

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

// Events
'update:modelValue': {
description: 'Event triggered when value changes',
control: {
type: null,
},
},
},
};

export const Primary = {
label: 'Primary',
args: {
size: 'medium',
disabled: false,
multiple: false,
default: 'Checkbox text',
},
};
50 changes: 50 additions & 0 deletions frontend/src/shared/ui-kit/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<label
class="c-checkbox"
:class="[
`c-checkbox--${props.size}`,
props.multiple && 'c-checkbox--multiple',
]"
>
<input v-model="checked" type="checkbox" :value="props.value" :disabled="props.disabled">
<span class="flex flex-col">
<slot />
<p>This is desc</p>
</span>
</label>
</template>

<script setup lang="ts">
import { CheckboxSize } from '@/shared/ui-kit/checkbox/types/CheckboxSize';
import { computed, withDefaults } from 'vue';
const props = withDefaults(defineProps<{
size?: CheckboxSize,
modelValue: string | boolean,
value?: string | boolean,
disabled?: boolean,
multiple?: boolean,
}>(), {
size: 'medium',
value: true,
disabled: false,
multiple: false,
});
const emit = defineEmits<{(e: 'update:modelValue', value: string | boolean): any}>();
const checked = computed<string | boolean>({
get() {
return props.modelValue;
},
set(val: string | boolean) {
emit('update:modelValue', val);
},
});
</script>

<script lang="ts">
export default {
name: 'CrCheckbox',
};
</script>
95 changes: 95 additions & 0 deletions frontend/src/shared/ui-kit/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.c-checkbox {
font-size: var(--cr-checkbox-font-size);
line-height: var(--cr-checkbox-line-height);
font-weight: var(--cr-checkbox-text-font-weight);
color: var(--cr-checkbox-text-color);
@apply flex flex-wrap relative;

input {
height: var(--cr-checkbox-size);
width: var(--cr-checkbox-size);
border: rem(1) solid var(--cr-checkbox-border);
background: var(--cr-checkbox-background);
border-radius: var(--cr-checkbox-border-radius);
box-shadow: var(--cr-checkbox-shadow);

--cr-checkbox-border: var(--cr-checkbox-unchecked-border);
--cr-checkbox-background: var(--cr-checkbox-unchecked-background);

@apply transition-all appearance-none p-0 my-0 ml-0 inline-block mr-2 cursor-pointer;

// Text
& + span{
@apply cursor-pointer;
}

// Icon
&:before{
content: "\eb7b";
font-family: 'remixicon', serif;
position: absolute;
left: 0;
top: 0;
color: var(--cr-checkbox-icon);
line-height: var(--cr-checkbox-size);
width: var(--cr-checkbox-size);
font-size: var(--cr-checkbox-size);

--cr-checkbox-icon: var(--cr-checkbox-unchecked-icon);
}

// Checked
&:checked{
--cr-checkbox-border: var(--cr-checkbox-checked-border);
--cr-checkbox-background: var(--cr-checkbox-checked-background);
--cr-checkbox-icon: var(--cr-checkbox-checked-icon);
}

// Disabled
&:disabled {
--cr-checkbox-border: var(--cr-checkbox-disabled-unchecked-border);
--cr-checkbox-background: var(--cr-checkbox-disabled-unchecked-background);
--cr-checkbox-icon: var(--cr-checkbox-disabled-unchecked-icon);
@apply cursor-not-allowed;

&:checked {
--cr-checkbox-border: var(--cr-checkbox-disabled-checked-border);
--cr-checkbox-background: var(--cr-checkbox-disabled-checked-background);
--cr-checkbox-icon: var(--cr-checkbox-disabled-checked-icon);
}

& + span{
@apply cursor-not-allowed;
}
}
}

// Checkbox sizes
&--small {
--cr-checkbox-size: var(--cr-checkbox-small-size);
--cr-checkbox-font-size: var(--cr-checkbox-small-font-size);
--cr-checkbox-line-height: var(--cr-checkbox-small-line-height);
}

&--medium {
--cr-checkbox-size: var(--cr-checkbox-medium-size);
--cr-checkbox-font-size: var(--cr-checkbox-medium-font-size);
--cr-checkbox-line-height: var(--cr-checkbox-medium-line-height);
}

// Multiple state
// Change icon to subtract-line
&--multiple {
input:before{
content: "\f1af";
}
}

p{
font-size: var(--cr-checkbox-description-font-size);
line-height: var(--cr-checkbox-description-line-height);
font-weight: var(--cr-checkbox-description-font-weight);
color: var(--cr-checkbox-description-color);
margin-top: var(--cr-checkbox-description-spacing);
}
}
6 changes: 6 additions & 0 deletions frontend/src/shared/ui-kit/checkbox/types/CheckboxSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const checkboxSizes = [
'small',
'medium',
] as const;

export type CheckboxSize = typeof checkboxSizes[number];
1 change: 1 addition & 0 deletions frontend/src/shared/ui-kit/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'button/button';
@import 'card/card';
@import 'checkbox/checkbox';