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

IT-6115 tile has border color prop #456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion lib/js/components/DatePickers/DatePicker/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
:interactive="isInteractive"
:additional-text="additionalText"
:color="color as TileColors"
:border-color="borderColor"
:state="state as TileStates"
:icon-right="tileIcon"
:is-icon-right-hidden-on-mobile="isIconHiddenOnMobile"
Expand Down Expand Up @@ -139,7 +140,7 @@
<script lang="ts">
import { defineComponent, PropType, Ref, ref, toRaw, watch } from 'vue';

import DsTile from '../../Tile';
import DsTile, { TILE_BORDER_COLORS } from '../../Tile';
import { IconItem, ICONS } from '../../Icons/Icon';
import DatePickerBox from '../DatePickerBox';

Expand Down Expand Up @@ -286,6 +287,22 @@ export default defineComponent({
};
},
computed: {
borderColor() {
return {
[DATE_PICKER_COLORS.NEUTRAL]: this.isInteractive
? TILE_BORDER_COLORS.PRIMARY
: TILE_BORDER_COLORS.NEUTRAL_WEAK,
[DATE_PICKER_COLORS.NEUTRAL_WEAK]: this.isInteractive
? TILE_BORDER_COLORS.PRIMARY
: TILE_BORDER_COLORS.NEUTRAL_WEAK,
[DATE_PICKER_COLORS.DANGER]: this.isInteractive
? TILE_BORDER_COLORS.DANGER
: TILE_BORDER_COLORS.DANGER_WEAK,
[DATE_PICKER_COLORS.WARNING]: this.isInteractive
? TILE_BORDER_COLORS.WARNING
: TILE_BORDER_COLORS.WARNING_WEAK,
}[this.color];
},
eyebrowText() {
if (!this.date) {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:state="state"
:eyebrow-ellipsis="eyebrowEllipsis"
:text-ellipsis="textEllipsis"
:has-border="hasBorder"
:border-color="borderColor"
/>
</div>
</template>
Expand Down
19 changes: 19 additions & 0 deletions lib/js/components/Tile/Tile.consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ export const TILE_STATES = {
} as const;

export type TileStates = Value<typeof TILE_STATES>;

export const TILE_BORDER_COLORS = {
NEUTRAL: 'neutral',
NEUTRAL_WEAK: 'neutralWeak',
PRIMARY: 'primary',
PRIMARY_WEAK: 'primaryWeak',
SUCCESS: 'success',
SUCCESS_WEAK: 'successWeak',
FAIL: 'fail',
FAIL_WEAK: 'failWeak',
DANGER: 'danger',
DANGER_WEAK: 'dangerWeak',
WARNING: 'warning',
WARNING_WEAK: 'warningWeak',
INFO: 'info',
INFO_WEAK: 'infoWeak',
} as const;

export type TileBorderColors = Value<typeof TILE_BORDER_COLORS>;
43 changes: 39 additions & 4 deletions lib/js/components/Tile/Tile.sb.shared.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ICONS } from '../Icons/Icon';
import { TILE_COLORS, TILE_STATES } from './Tile.consts';
import { TILE_BORDER_COLORS, TILE_COLORS, TILE_STATES } from './Tile.consts';
import { Args, ArgTypes } from '@storybook/vue3';
import DsBanner, { BANNER_COLORS } from '../Banner';

export const template = (componentTag: string) => `
<div style="display: flex; row-gap: 16px; flex-direction: column">
<${componentTag}
:additional-text="additionalText"
:color="color"
Expand All @@ -16,17 +18,46 @@ export const template = (componentTag: string) => `
:state="state"
:text-ellipsis="textEllipsis"
:text="text"
:has-border="hasBorder"
/>`;
:border-color="borderColor"
/>
<ds-banner :color="BANNER_COLORS.WARNING" title="Taka kombinacja koloru komponentu z kolorem bordera jest niezgodna z design systemem!" v-if="borderColor && !allowedColorsToBorderColorsMap[color].includes(borderColor)" />
</div>
`;

export const data = () => ({
ICONS: Object.freeze(ICONS),
BANNER_COLORS: Object.freeze(BANNER_COLORS),
allowedColorsToBorderColorsMap: {
[TILE_COLORS.NEUTRAL]: [
TILE_BORDER_COLORS.NEUTRAL,
TILE_BORDER_COLORS.NEUTRAL_WEAK,
TILE_BORDER_COLORS.PRIMARY,
TILE_BORDER_COLORS.PRIMARY_WEAK,
],
[TILE_COLORS.NEUTRAL_WEAK]: [
TILE_BORDER_COLORS.NEUTRAL,
TILE_BORDER_COLORS.NEUTRAL_WEAK,
TILE_BORDER_COLORS.PRIMARY,
TILE_BORDER_COLORS.PRIMARY_WEAK,
],
[TILE_COLORS.PRIMARY]: [TILE_BORDER_COLORS.PRIMARY, TILE_BORDER_COLORS.PRIMARY_WEAK],
[TILE_COLORS.SUCCESS]: [TILE_BORDER_COLORS.SUCCESS, TILE_BORDER_COLORS.SUCCESS_WEAK],
[TILE_COLORS.FAIL]: [TILE_BORDER_COLORS.FAIL, TILE_BORDER_COLORS.FAIL_WEAK],
[TILE_COLORS.DANGER]: [TILE_BORDER_COLORS.DANGER, TILE_BORDER_COLORS.DANGER_WEAK],
[TILE_COLORS.WARNING]: [TILE_BORDER_COLORS.WARNING, TILE_BORDER_COLORS.WARNING_WEAK],
[TILE_COLORS.INFO]: [TILE_BORDER_COLORS.INFO, TILE_BORDER_COLORS.INFO_WEAK],
},
});

export const components = {
DsBanner,
};

export const args = {
interactive: true,
color: TILE_COLORS.NEUTRAL,
hasBorder: false,
borderColor: null,
isBorderWeak: false,
iconLeft: null,
iconRight: null,
isIconRightHiddenOnMobile: false,
Expand All @@ -52,6 +83,10 @@ export const argTypes = {
control: 'select',
options: [...Object.values(TILE_COLORS)],
},
borderColor: {
control: 'select',
options: [null, ...Object.values(TILE_BORDER_COLORS)],
},
state: {
control: 'select',
options: [...Object.values(TILE_STATES)],
Expand Down
8 changes: 4 additions & 4 deletions lib/js/components/Tile/Tile.shared.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropType, toRaw } from 'vue';
import { ICONS } from '../Icons/Icon';
import { TILE_COLORS, TILE_STATES, TileColors, TileStates } from './Tile.consts';
import { TILE_COLORS, TILE_STATES, TileBorderColors, TileColors, TileStates } from './Tile.consts';
import { Value } from '../../utils/type.utils';

export const props = {
Expand Down Expand Up @@ -64,8 +64,8 @@ export const props = {
type: Boolean,
default: true,
},
hasBorder: {
type: Boolean,
default: false,
borderColor: {
type: String as PropType<TileBorderColors>,
default: null,
},
};
4 changes: 2 additions & 2 deletions lib/js/components/Tile/Tile.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Tile from './Tile.vue';
import { TILE_STATES } from './Tile.consts';

import type { Args, Meta, StoryObj } from '@storybook/vue3';
import { args, argTypes, data, template } from './Tile.sb.shared';
import { args, argTypes, components, data, template } from './Tile.sb.shared';
import type { ComponentProps } from 'vue-component-type-helpers';
import { withActions } from '@storybook/addon-actions/decorator';

Expand All @@ -15,7 +15,7 @@ const meta: Meta<TileProps> = {
component: Tile,
decorators: [withActions],
render: (args) => ({
components: { Tile },
components: { ...components, Tile },
setup() {
return args;
},
Expand Down
Loading