Skip to content
Snippets Groups Projects
Commit 234f5762 authored by Дмитрий Малюгин's avatar Дмитрий Малюгин :clock4:
Browse files

fix: component's colors functional

parent 7ab6d5ce
No related branches found
No related tags found
1 merge request!3Table (partially), Checkbox, Tag, Select and Knob
...@@ -325,7 +325,8 @@ const sliderValue = ref(1); ...@@ -325,7 +325,8 @@ const sliderValue = ref(1);
{ {
label: 'font-family', label: 'font-family',
theme: 'green', theme: 'green',
color: 'white', color: 'red',
darknessColor: '500',
link: 'https://developer.mozilla.org/en-US/docs/Web/CSS/font-family', link: 'https://developer.mozilla.org/en-US/docs/Web/CSS/font-family',
linkBlank: true, linkBlank: true,
textStyle: 'bold', textStyle: 'bold',
...@@ -333,6 +334,8 @@ const sliderValue = ref(1); ...@@ -333,6 +334,8 @@ const sliderValue = ref(1);
{ {
label: 'Second', label: 'Second',
theme: 'red', theme: 'red',
color: 'sky',
darknessColor: '500',
darknessTheme: '600', darknessTheme: '600',
textStyle: 'italic', textStyle: 'italic',
}, },
......
...@@ -32,8 +32,8 @@ export const convertThemeToColor = (theme: TThemeColor, darkness: TDarkness | st ...@@ -32,8 +32,8 @@ export const convertThemeToColor = (theme: TThemeColor, darkness: TDarkness | st
*/ */
export const convertThemeToSecondaryColor = (theme: TThemeColor, darkness: TDarkness | string = '500') => { export const convertThemeToSecondaryColor = (theme: TThemeColor, darkness: TDarkness | string = '500') => {
return theme === 'white' || theme === 'black' return theme === 'white' || theme === 'black'
? convertWhiteOrBlackToColor(theme, darkness) ? convertWhiteOrBlackToColor(theme, darkness as TDarkness)
: convertThemeToColor(theme, String(100 + ((darkness + 600) % 900))); : convertThemeToColor(theme, String(100 + ((+darkness + 600) % 900)));
}; };
export const convertThemeToTextColor = (theme: TThemeColor, darkness: TDarkness | string = '500') => { export const convertThemeToTextColor = (theme: TThemeColor, darkness: TDarkness | string = '500') => {
......
...@@ -81,6 +81,7 @@ export interface IDrawerProps { ...@@ -81,6 +81,7 @@ export interface IDrawerProps {
theme?: TThemeColor; theme?: TThemeColor;
textColor?: TThemeColor; textColor?: TThemeColor;
darknessTheme?: TDarkness; darknessTheme?: TDarkness;
darknessTextColor?: TDarkness;
modal?: boolean; modal?: boolean;
dismissible?: boolean; dismissible?: boolean;
closeIcon?: TIcons; closeIcon?: TIcons;
...@@ -90,9 +91,7 @@ export interface IDrawerProps { ...@@ -90,9 +91,7 @@ export interface IDrawerProps {
export interface IModalProps { export interface IModalProps {
theme?: TThemeColor; theme?: TThemeColor;
textColor?: TThemeColor;
darknessTheme?: TDarkness; darknessTheme?: TDarkness;
darknessTextColor?: TDarkness;
width?: string; width?: string;
height?: string; height?: string;
position?: TExpandedPosition; position?: TExpandedPosition;
......
...@@ -27,6 +27,7 @@ const meta: Meta = { ...@@ -27,6 +27,7 @@ const meta: Meta = {
headerDivider: { control: 'boolean' }, headerDivider: { control: 'boolean' },
footerDivider: { control: 'boolean' }, footerDivider: { control: 'boolean' },
darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] }, darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
darknessTextColor: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
theme: { theme: {
control: 'select', control: 'select',
options: [ options: [
......
...@@ -28,6 +28,7 @@ const meta: Meta = { ...@@ -28,6 +28,7 @@ const meta: Meta = {
options: ['top', 'right', 'bottom', 'left', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'], options: ['top', 'right', 'bottom', 'left', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'],
}, },
darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] }, darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
darknessTextColor: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
theme: { theme: {
control: 'select', control: 'select',
options: [ options: [
...@@ -48,6 +49,26 @@ const meta: Meta = { ...@@ -48,6 +49,26 @@ const meta: Meta = {
'black', 'black',
], ],
}, },
textColor: {
control: 'select',
options: [
'white',
'blue',
'sky',
'cyan',
'teal',
'green',
'yellow',
'orange',
'pink',
'fuchsia',
'purple',
'indigo',
'rose',
'red',
'black',
],
},
}, },
args: {}, args: {},
} satisfies Meta<typeof Modal>; } satisfies Meta<typeof Modal>;
......
...@@ -9,6 +9,7 @@ const props = withDefaults(defineProps<IModalProps>(), { ...@@ -9,6 +9,7 @@ const props = withDefaults(defineProps<IModalProps>(), {
dismissible: false, dismissible: false,
theme: 'white', theme: 'white',
darknessTheme: '500', darknessTheme: '500',
darknessTextColor: '500',
width: '30%', width: '30%',
height: '30%', height: '30%',
headerDivider: false, headerDivider: false,
......
...@@ -21,7 +21,6 @@ const meta: Meta = { ...@@ -21,7 +21,6 @@ const meta: Meta = {
maxHeight: { control: 'text' }, maxHeight: { control: 'text' },
padding: { control: 'text' }, padding: { control: 'text' },
darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] }, darknessTheme: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
darknessTextColor: { control: 'select', options: ['100', '200', '300', '400', '500', '600', '700', '800', '900'] },
theme: { theme: {
control: 'select', control: 'select',
options: [ options: [
...@@ -42,26 +41,6 @@ const meta: Meta = { ...@@ -42,26 +41,6 @@ const meta: Meta = {
'black', 'black',
], ],
}, },
textColor: {
control: 'select',
options: [
'white',
'blue',
'sky',
'cyan',
'teal',
'green',
'yellow',
'orange',
'pink',
'fuchsia',
'purple',
'indigo',
'rose',
'red',
'black',
],
},
}, },
args: {}, args: {},
} satisfies Meta<typeof Popup>; } satisfies Meta<typeof Popup>;
......
<script setup lang="ts"> <script setup lang="ts">
import type { IPopupProps } from '@interfaces/componentsProps'; import type { IPopupProps } from '@interfaces/componentsProps';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { convertThemeToColor, convertThemeToSecondaryColor, convertThemeToTextColor } from '@helpers/common'; import { convertThemeToColor, convertThemeToSecondaryColor } from '@helpers/common';
const props = withDefaults(defineProps<IPopupProps>(), { const props = withDefaults(defineProps<IPopupProps>(), {
parentSelector: 'body', parentSelector: 'body',
...@@ -15,11 +15,6 @@ const props = withDefaults(defineProps<IPopupProps>(), { ...@@ -15,11 +15,6 @@ const props = withDefaults(defineProps<IPopupProps>(), {
const active = defineModel<boolean>('active'); const active = defineModel<boolean>('active');
const themeColor = computed(() => convertThemeToColor(props.theme, props.darknessTheme)); const themeColor = computed(() => convertThemeToColor(props.theme, props.darknessTheme));
const secondaryColor = computed(() => convertThemeToSecondaryColor(props.theme, props.darknessTheme)); const secondaryColor = computed(() => convertThemeToSecondaryColor(props.theme, props.darknessTheme));
const color = computed(() =>
props.textColor
? convertThemeToColor(props.textColor, props.darknessTextColor)
: convertThemeToTextColor(props.theme, props.darknessTheme),
);
const top = ref(); const top = ref();
const left = ref(); const left = ref();
...@@ -52,7 +47,7 @@ document.addEventListener('pointerdown', (e) => { ...@@ -52,7 +47,7 @@ document.addEventListener('pointerdown', (e) => {
oncontextmenu="return false" oncontextmenu="return false"
id="popup" id="popup"
@pointerdown.stop="" @pointerdown.stop=""
:style="`top: ${top}px; left: ${left}px; opacity: ${active ? 1 : 0}; pointer-events: ${active ? 'auto' : 'none'}; padding: ${padding}; color: ${color}`" :style="`top: ${top}px; left: ${left}px; opacity: ${active ? 1 : 0}; pointer-events: ${active ? 'auto' : 'none'}; padding: ${padding}`"
> >
<div :style="`max-width: ${maxWidth}; max-height: ${maxHeight}; overflow: auto; padding-right: 5px`"> <div :style="`max-width: ${maxWidth}; max-height: ${maxHeight}; overflow: auto; padding-right: 5px`">
<slot /> <slot />
......
...@@ -85,26 +85,6 @@ const meta: Meta = { ...@@ -85,26 +85,6 @@ const meta: Meta = {
'black', 'black',
], ],
}, },
border: {
control: 'select',
options: [
'white',
'blue',
'sky',
'cyan',
'teal',
'green',
'yellow',
'orange',
'pink',
'fuchsia',
'purple',
'indigo',
'rose',
'red',
'black',
],
},
disabled: { control: 'boolean' }, disabled: { control: 'boolean' },
}, },
args: {}, args: {},
...@@ -136,22 +116,23 @@ export const LargeFull: Story = { ...@@ -136,22 +116,23 @@ export const LargeFull: Story = {
{ {
label: 'First', label: 'First',
color: 'white', color: 'white',
darknessColor: '900',
backgroundColor: 'black', backgroundColor: 'black',
}, },
{ {
label: 'Second', label: 'Second',
color: 'red', color: 'red',
activeColor: 'blue', activeColor: 'blue',
darknessColor: '700',
backgroundColor: 'yellow', backgroundColor: 'yellow',
}, },
{ {
label: 'Third', label: 'Third',
activeColor: 'green', activeColor: 'green',
darknessColor: '700',
backgroundColor: 'purple', backgroundColor: 'purple',
}, },
], ],
border: 'sky',
activeBackgroundColor: 'red', activeBackgroundColor: 'red',
rounded: true, rounded: true,
disabled: false, disabled: false,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { computed } from 'vue'; import { computed } from 'vue';
import type { ISBProps } from '@interfaces/componentsProps'; import type { ISBProps } from '@interfaces/componentsProps';
import { convertThemeToSecondaryColor, convertThemeToColor, convertThemeToTextColor } from '@helpers/common'; import { convertThemeToSecondaryColor, convertThemeToColor, convertThemeToTextColor } from '@helpers/common';
import type { ISBOption } from '@interfaces/componentsProp';
const props = withDefaults(defineProps<ISBProps>(), { const props = withDefaults(defineProps<ISBProps>(), {
size: 'normal', size: 'normal',
...@@ -19,10 +20,8 @@ const color = computed(() => ...@@ -19,10 +20,8 @@ const color = computed(() =>
? convertThemeToColor(props.textColor, props.darknessTextColor) ? convertThemeToColor(props.textColor, props.darknessTextColor)
: convertThemeToTextColor(props.theme, props.darknessTheme), : convertThemeToTextColor(props.theme, props.darknessTheme),
); );
const activeBackgroundColorComputed = computed(() => const activeBGColorComputed = computed(() =>
props.activeBackgroundColor convertThemeToColor(props.activeBackgroundColor, props.darknessActiveBackgroundColor),
? convertThemeToColor(props.activeBackgroundColor, props.darknessActiveBackgroundColor)
: '',
); );
const borderColor = computed(() => convertThemeToSecondaryColor(props.theme, props.darknessTheme)); const borderColor = computed(() => convertThemeToSecondaryColor(props.theme, props.darknessTheme));
const textSize = computed(() => { const textSize = computed(() => {
...@@ -58,6 +57,30 @@ const buttonHeight = computed(() => { ...@@ -58,6 +57,30 @@ const buttonHeight = computed(() => {
} }
return '40px'; return '40px';
}); });
const calcItemColor = (item: ISBOption) => {
if ((item.value && value.value === item.value) || String(value.value) === item.label) {
const activeColor = item.activeColor;
if (!activeColor) {
return color.value;
} else {
return convertThemeToColor(activeColor, item.darknessActiveColor ?? '500');
}
} else {
const itemColor = item.color;
if (!itemColor) {
return color.value;
} else {
return convertThemeToColor(itemColor, item.darknessColor ?? '500');
}
}
};
const calcBGColorItem = (item: ISBOption) => {
return (value.value && value.value === item.value) || String(value.value) === item.label
? activeBGColorComputed.value
: item.backgroundColor
? convertThemeToColor(item.backgroundColor, item.darknessBackgroundColor ?? '500')
: themeColor.value;
};
</script> </script>
<template> <template>
...@@ -89,7 +112,7 @@ const buttonHeight = computed(() => { ...@@ -89,7 +112,7 @@ const buttonHeight = computed(() => {
" "
> >
<span <span
:style="`background-color: ${activeBackgroundColorComputed && ((value && value === item.value) || value === item.label) ? activeBackgroundColorComputed : (convertThemeToColor(item.backgroundColor, item.darknessBackgroundColor ?? '500') ?? themeColor)}`" :style="`background-color: ${calcBGColorItem(item)}`"
:class="[ :class="[
'background', 'background',
{ {
...@@ -102,7 +125,7 @@ const buttonHeight = computed(() => { ...@@ -102,7 +125,7 @@ const buttonHeight = computed(() => {
></span> ></span>
<span <span
v-if="!item.isLabelHidden" v-if="!item.isLabelHidden"
:style="`color: ${(item.value && value === item.value) || value === item.label ? (convertThemeToColor(item.activeColor, item.darknessActiveColor ?? '500') ?? color) : (convertThemeToColor(item.color, item.darknessColor ?? '500') ?? color)}; font-size: ${textSize}`" :style="`color: ${calcItemColor(item)}; font-size: ${textSize}`"
:class="[ :class="[
{ {
bold: item.textStyle === 'bold', bold: item.textStyle === 'bold',
......
...@@ -125,8 +125,8 @@ export const Full: Story = { ...@@ -125,8 +125,8 @@ export const Full: Story = {
color: 'red', color: 'red',
iconAfter: 'DiceIcon', iconAfter: 'DiceIcon',
iconColor: 'red', iconColor: 'red',
darknessColor: 400, darknessColor: '300',
darknessIconColor: 400, darknessIconColor: '700',
children: [ children: [
{ {
label: '1-1-1-1', label: '1-1-1-1',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment