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

feat(QCheckbox): add labelSize props and redesign #306

Merged
merged 22 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2ec330d
feat(QCheckbox): add label size prop
VasiliyRusin Jun 15, 2022
7d9e53a
feat(QCheckbox): remove neumorphism inner shadows add accent color
VasiliyRusin Jun 17, 2022
00176ea
feat(QCheckbox): fix import type
VasiliyRusin Jun 17, 2022
954b8ee
feat(QCheckbox): rename Label Size type
VasiliyRusin Jun 17, 2022
a525bc8
feat(QCheckbox): remove unused vars, add label color, change line-height
VasiliyRusin Jun 17, 2022
785069e
feat(QCheckbox): set label colors exact as in figma
VasiliyRusin Jun 20, 2022
6f2efa8
feat(QCheckbox): add docs for small label
VasiliyRusin Jun 22, 2022
ca1fcfc
feat(RCheckbox): fix code style
VasiliyRusin Jun 22, 2022
90709d3
feat(RCheckbox): add indeterminate class
VasiliyRusin Jun 22, 2022
d3c3fdc
feat(QCheckbox): fix code style
VasiliyRusin Jun 22, 2022
31e9fed
feat(QCheckbox): add indeterminate class
VasiliyRusin Jun 22, 2022
eb26279
Merge remote-tracking branch 'origin/q-checkbox-redesign' into q-chec…
VasiliyRusin Jun 22, 2022
c5d8abb
feat(QCheckbox): cast to type Boolean
VasiliyRusin Jun 23, 2022
ba131f3
feat(QRadio): fix indeterminate props to isIntermediate computed
VasiliyRusin Jun 23, 2022
0345253
feat(QCheckbox): fix indeterminate props to isIntermediate computed, …
VasiliyRusin Jun 23, 2022
5b11c47
feat(QCheckbox): add types for props and computed for classes
VasiliyRusin Jun 23, 2022
673bebc
Merge branch 'main' into q-checkbox-redesign
VasiliyRusin Jun 23, 2022
0bfb55d
feat(QCheckbox): get ref value
VasiliyRusin Jun 23, 2022
d7546d8
feat(QCheckbox): change camelCase to kebab-case at props in story
VasiliyRusin Jun 23, 2022
92e7093
fix(QCheckbox): add story args
VasiliyRusin Jul 1, 2022
bbce6c7
Merge branch 'main' of github.com:Qvant-lab/qui-max into q-checkbox-r…
cheesytim Jul 12, 2022
a4680d0
fix: default story
cheesytim Jul 12, 2022
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
12 changes: 11 additions & 1 deletion src/qComponents/QCheckbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ import Checkbox from './src/QCheckbox.vue';

export const QCheckbox = withInstall(Checkbox);

export type { QCheckboxProps, QCheckboxInstance } from './src/types';
export type {
QCheckboxProps,
QCheckboxInstance,
QCheckboxPropModelValue,
QCheckboxPropLabel,
QCheckboxPropIndeterminate,
QCheckboxPropDisabled,
QCheckboxPropRootTag,
QCheckboxPropValidateEvent,
QCheckboxPropLabelSize
} from './src/types';
112 changes: 86 additions & 26 deletions src/qComponents/QCheckbox/src/QCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,20 @@
<component
:is="rootTag || 'label'"
class="q-checkbox"
:class="{
'q-checkbox_disabled': isDisabled,
'q-checkbox_checked': isChecked
}"
:class="qCheckboxClasses"
@click.prevent="handleCheckboxClick"
>
<span
class="q-checkbox__input"
:class="{
'q-checkbox__input_disabled': isDisabled,
'q-checkbox__input_checked': isChecked,
'q-checkbox__input_focus': focus
}"
:tabindex="indeterminate ? 0 : false"
:role="indeterminate ? 'checkbox' : false"
:aria-checked="indeterminate ? 'mixed' : false"
:class="qCheckboxInputClasses"
:tabindex="isIndeterminate ? 0 : undefined"
:role="isIndeterminate ? 'checkbox' : undefined"
:aria-checked="isIndeterminate ? 'mixed' : false"
>
<span class="q-checkbox__inner">
<span
class="q-checkbox__inner-icon"
:class="{
'q-icon-minus': indeterminate,
'q-icon-check': isChecked
}"
:class="qCheckboxInnerIconClasses"
/>
</span>
<input
Expand All @@ -34,7 +24,7 @@
:value="isChecked"
class="q-checkbox__original"
type="checkbox"
:aria-hidden="indeterminate ? 'true' : 'false'"
:aria-hidden="isIndeterminate ? 'true' : 'false'"
:disabled="isDisabled"
@focus="focus = true"
@blur="focus = false"
Expand All @@ -43,6 +33,7 @@
<span
v-if="$slots.default || label"
class="q-checkbox__label"
:class="labelClass"
>
<slot>{{ label }}</slot>
</span>
Expand All @@ -51,14 +42,26 @@

<script lang="ts">
import { computed, defineComponent, inject, watch, ref } from 'vue';
import type { PropType } from 'vue';

import { validateArray } from '@/qComponents/helpers';
import type { QCheckboxGroupProvider } from '@/qComponents/QCheckboxGroup';
import type { QFormProvider } from '@/qComponents/QForm';
import type { QFormItemProvider } from '@/qComponents/QFormItem';

import type { Nullable } from '#/helpers';
import type { Nullable, ClassValue } from '#/helpers';

import type { QCheckboxProps, QCheckboxInstance } from './types';
import type {
QCheckboxProps,
QCheckboxInstance,
QCheckboxPropLabelSize,
QCheckboxPropModelValue,
QCheckboxPropLabel,
QCheckboxPropIndeterminate,
QCheckboxPropDisabled,
QCheckboxPropRootTag,
QCheckboxPropValidateEvent
} from './types';

export default defineComponent({
name: 'QCheckbox',
Expand All @@ -70,24 +73,50 @@ export default defineComponent({
/**
* Array for group, Boolean for single
*/
modelValue: { type: Boolean, default: null },
modelValue: {
type: Boolean as PropType<QCheckboxPropModelValue>,
default: null
},
/**
* Checkbox label
*/
label: { type: String, default: null },
label: {
type: String as PropType<QCheckboxPropLabel>,
default: null
},
/**
* wheteher Checkbox is indeterminate
*/
indeterminate: { type: Boolean, default: false },
indeterminate: {
type: Boolean as PropType<QCheckboxPropIndeterminate>,
default: false
},
/**
* wheteher Checkbox is disabled
*/
disabled: { type: Boolean, default: false },
rootTag: { type: String, default: 'label' },
disabled: {
type: Boolean as PropType<QCheckboxPropDisabled>,
default: false
},
rootTag: {
type: String as PropType<QCheckboxPropRootTag>,
default: 'label'
},
/**
* wheteher is validate parent q-form if present
*/
validateEvent: { type: Boolean, default: false }
validateEvent: {
type: Boolean as PropType<QCheckboxPropValidateEvent>,
default: false
},
/**
* label size
*/
labelSize: {
type: String as PropType<QCheckboxPropLabelSize>,
default: 'regular',
validator: validateArray<QCheckboxPropLabelSize>(['regular', 'small'])
}
},

emits: [
Expand Down Expand Up @@ -145,6 +174,32 @@ export default defineComponent({
: props.disabled || (qForm?.disabled.value ?? false)
);

const isIndeterminate = computed<boolean>(
() => !isChecked.value && Boolean(props.indeterminate)
);

const labelClass = computed<ClassValue>(
() => `q-checkbox__label_size_${props.labelSize ?? 'regular'}`
);

const qCheckboxClasses = computed<ClassValue>(() => ({
'q-checkbox_disabled': isDisabled.value,
'q-checkbox_checked': isChecked.value,
'q-checkbox_indeterminate': isIndeterminate.value
}));

const qCheckboxInputClasses = computed<ClassValue>(() => ({
'q-checkbox__input_disabled': isDisabled.value,
'q-checkbox__input_checked': isChecked.value,
'q-checkbox__input_indeterminate': isIndeterminate.value,
'q-checkbox__input_focus': focus.value
}));

const qCheckboxInnerIconClasses = computed<ClassValue>(() => ({
'q-icon-minus': isIndeterminate.value,
'q-icon-check': isChecked.value
}));

const handleCheckboxClick = (event: Event): void => {
if (isDisabled.value) return;

Expand Down Expand Up @@ -188,11 +243,16 @@ export default defineComponent({
return {
focus,
isChecked,
isIndeterminate,
isLimitDisabled,
isDisabled,
nativeClick,
checkboxInput,
handleCheckboxClick
handleCheckboxClick,
labelClass,
qCheckboxClasses,
qCheckboxInputClasses,
qCheckboxInnerIconClasses
};
}
});
Expand Down
54 changes: 30 additions & 24 deletions src/qComponents/QCheckbox/src/q-checkbox.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
.q-checkbox {
--checkbox-color-base: var(--color-primary-black);
--checkbox-color-base: rgb(var(--color-base-regular-rgb) / 96%);
--checkbox-color-disabled: rgb(var(--color-rgb-gray) / 64%);
--checkbox-background-color-base: var(--color-tertiary-gray-ultra-light);
--checkbox-background-color-hover: var(--color-tertiary-gray);
--checkbox-background-color-focus: var(--color-tertiary-gray-ultra-light);
--checkbox-background-color-checked: var(--color-tertiary-gray-ultra-light);
--checkbox-background-color-disabled: var(--color-tertiary-gray);
--checkbox-mark-color-base: var(--color-primary-blue);
--checkbox-mark-color-base: var(--color-accent-secondary-main);
--checkbox-mark-color-disabled: rgb(var(--color-rgb-gray) / 64%);
--checkbox-box-shadow-base: -1px -1px 3px rgb(var(--color-rgb-white) / 25%),
1px 1px 3px rgb(var(--color-rgb-blue) / 40%),
inset -1px -1px 1px rgb(var(--color-rgb-white) / 70%),
inset 1px 1px 2px rgb(var(--color-rgb-blue) / 20%);
--checkbox-box-shadow-focus: -1px -1px 3px rgb(var(--color-rgb-white) / 25%),
1px 1px 3px rgb(var(--color-rgb-blue) / 40%),
4px 4px 10px rgb(var(--color-rgb-blue) / 40%),
-4px -4px 10px rgb(var(--color-rgb-white) / 25%),
inset -1px -1px 1px rgb(var(--color-rgb-white) / 70%),
inset 1px 1px 2px rgb(var(--color-rgb-blue) / 20%);
--checkbox-box-shadow-base: 1px 1px 3px rgb(var(--color-rgb-blue) / 40%);
--checkbox-box-shadow-focus: 1px 1px 3px rgb(var(--color-rgb-blue) / 40%),
inset 0 0 0 1px var(--color-accent-secondary-main);

position: relative;
display: inline-flex;
Expand All @@ -33,16 +24,31 @@

&__label {
padding-left: 16px;
margin-top: 3px;
font-size: var(--font-size-base);
line-height: 18px;
color: var(--checkbox-color-base);
word-break: break-word;
white-space: normal;

.q-checkbox_disabled & {
color: var(--checkbox-color-disabled);
cursor: not-allowed;
}

&_size {
&_regular {
margin-top: 2px;
font-size: 14px;
line-height: 20px;
}

&_small {
--checkbox-color-base: rgb(var(--color-base-regular-rgb) / 64%);

margin-top: 5px;
font-size: 10px;
line-height: 14px;
}
}
}

&__input {
Expand All @@ -67,6 +73,10 @@
border-radius: var(--border-radius-base);
box-shadow: var(--checkbox-box-shadow-base);

&:hover {
background-color: var(--checkbox-background-color-hover);
}

&-icon {
position: absolute;
top: 4px;
Expand All @@ -80,15 +90,12 @@

.q-checkbox_checked &,
.q-checkbox__input_indeterminate & {
background-color: var(--checkbox-background-color-checked);

&::after {
opacity: 1;
}
}

.q-checkbox__input_focus & {
background-color: var(--checkbox-background-color-focus);
box-shadow: var(--checkbox-box-shadow-focus);
}

Expand All @@ -102,11 +109,10 @@
}
}

.q-checkbox__input_focus &,
.q-checkbox_checked &,
.q-checkbox__input_indeterminate & {
&:hover {
background-color: var(--checkbox-background-color-hover);
.q-form-item_is-error & {
&,
.q-checkbox__input_focus {
border: var(--border-error);
}
}
}
Expand Down
28 changes: 21 additions & 7 deletions src/qComponents/QCheckbox/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import type { Ref, ComputedRef } from 'vue';

import type { Nullable } from '#/helpers';
import type { Nullable, ClassValue } from '#/helpers';

export type QCheckboxPropModelValue = Nullable<boolean>;
export type QCheckboxPropLabel = Nullable<string>;
export type QCheckboxPropIndeterminate = Nullable<boolean>;
export type QCheckboxPropDisabled = Nullable<boolean>;
export type QCheckboxPropRootTag = Nullable<string>;
export type QCheckboxPropValidateEvent = Nullable<boolean>;
export type QCheckboxPropLabelSize = Nullable<'regular' | 'small'>;

export interface QCheckboxProps {
modelValue: Nullable<boolean>;
label: Nullable<string>;
indeterminate: Nullable<boolean>;
disabled: Nullable<boolean>;
rootTag: Nullable<string>;
validateEvent: Nullable<boolean>;
modelValue: QCheckboxPropModelValue;
label: QCheckboxPropLabel;
indeterminate: QCheckboxPropIndeterminate;
disabled: QCheckboxPropDisabled;
rootTag: QCheckboxPropRootTag;
validateEvent: QCheckboxPropValidateEvent;
labelSize: QCheckboxPropLabelSize;
}

export interface QCheckboxInstance {
focus: Ref<boolean>;
isChecked: ComputedRef<boolean>;
isIndeterminate: ComputedRef<boolean>;
isLimitDisabled: ComputedRef<boolean>;
isDisabled: ComputedRef<boolean>;
nativeClick: () => void;
handleCheckboxClick: (event: Event) => void;
checkboxInput: Ref<Nullable<HTMLInputElement>>;
labelClass: ComputedRef<ClassValue>;
qCheckboxClasses: ComputedRef<ClassValue>;
qCheckboxInputClasses: ComputedRef<ClassValue>;
qCheckboxInnerIconClasses: ComputedRef<ClassValue>;
}
2 changes: 2 additions & 0 deletions src/vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
--color-secondary-orange: #f95e2d;
--color-secondary-green: #40ba3e;
--color-secondary-yellow: #f2d22b;
--color-accent-secondary-main: #4262f0;
--color-tertiary-white: #fff;
--color-tertiary-gray-ultra-light: #fafafa;
--color-tertiary-gray-lighter: #f4f4f6;
Expand All @@ -19,6 +20,7 @@
--color-tertiary-gray-ultra-dark: #c4c4c4;
--color-tertiary-gray-ultra-darker: #adacae;
--color-tertiary-gray-ultra-darker-rgb: 173 172 174;
--color-base-regular-rgb: 29 29 27;
--color-rgb-white: 255 255 255;
--color-rgb-blue: 174 174 192;
--color-rgb-gray: 29 28 26;
Expand Down
8 changes: 7 additions & 1 deletion stories/components/QCheckbox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const storyMetadata: Meta = {
title: 'Components/QCheckbox',
component: QCheckbox,
argTypes: {
modelValue: { control: { type: 'none' } }
modelValue: { control: { type: 'none' } },
labelSize: {
options: ['regular', 'small'],
control: { type: 'select' },
defaultValue: 'regular'
}
}
};

Expand All @@ -30,6 +35,7 @@ const Template: Story<QCheckboxProps> = args =>
:indeterminate="args.indeterminate"
:disabled="args.disabled"
:rootTag="args.rootTag"
:labelSize="args.labelSize"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кебаб

/>
`
});
Expand Down
Loading