Skip to content

Commit

Permalink
feat(tag): colour token updates (#310)
Browse files Browse the repository at this point in the history
* feat: colour token updates - tag

* feat: clickable tag variant

* chore: doc update

* chore: class name update

* chore: colour token update

* chore: minor fix

* chore: code cleanup

* fix: changed show all/ less button to kd-link

* chore: code cleanup - tag group and skeleton

* fix: keyboard controls for tag

* chore: comments and migration guide notes

* fix: outline-width value change
  • Loading branch information
jaideep08 authored Jan 9, 2025
1 parent 93b8f17 commit 1c4bf17
Show file tree
Hide file tree
Showing 9 changed files with 9,773 additions and 9,620 deletions.
18,814 changes: 9,407 additions & 9,407 deletions custom-elements.json

Large diffs are not rendered by default.

422 changes: 284 additions & 138 deletions src/components/reusable/tag/tag.scss

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions src/components/reusable/tag/tag.skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,16 @@ export class TagSkeleton extends LitElement {
@property({ type: String })
tagSize = 'sm';

/**
* Shade `'light'` (default) and `'dark'` for tag.
*/
@property({ type: String })
shade = 'light';

override render() {
const shadeClass = this.shade === 'dark' ? '-dark' : '';
const sizeClass = this.tagSize === 'md' ? 'tag-medium' : 'tag-small';

const tagClasses = {
tags: true,
[`${shadeClass}`]: true,
[`${sizeClass}`]: true,
};

return html`
<div class="${classMap(tagClasses)}" shade=${this.shade}>
<div class="${classMap(tagClasses)}">
<kyn-skeleton
shape="rectangle"
height="100%"
Expand Down
21 changes: 13 additions & 8 deletions src/components/reusable/tag/tag.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ export default {
options: ['sm', 'md'],
control: { type: 'select' },
},
shade: {
options: ['light', 'dark'],
control: { type: 'select' },
},
tagColor: {
options: [
'grey',
'spruce',
'failed',
'interactive',
'blue',
'error',
'warning',
'passed',
'success',
'cat01',
'cat02',
'cat03',
'cat04',
'cat05',
'cat06',
],
control: { type: 'select' },
},
Expand All @@ -39,6 +38,11 @@ export default {
type: 'boolean',
},
},
clickable: {
control: {
type: 'boolean',
},
},
},
parameters: {
design: {
Expand All @@ -51,10 +55,10 @@ export default {
const args = {
label: 'Tag Example',
tagSize: 'md',
shade: 'light',
tagColor: 'spruce',
disabled: false,
filter: false,
clickable: false,
noTruncation: false,
};

Expand All @@ -65,12 +69,13 @@ export const Tag = {
<kyn-tag
label=${args.label}
tagSize=${args.tagSize}
shade=${args.shade}
tagColor=${args.tagColor}
?disabled=${args.disabled}
?filter=${args.filter}
?clickable=${args.clickable}
?noTruncation=${args.noTruncation}
@on-close=${(e) => action(e.type)(e)}
@on-click=${(e) => action(e.type)(e)}
/></kyn-tag>
`;
},
Expand Down
65 changes: 56 additions & 9 deletions src/components/reusable/tag/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class Tag extends LitElement {
noTruncation = false;

/**
* Shade `'light'` (default) and `'dark'` for tag
* Determine if Tag is clickable.
*/
@property({ type: String })
shade = 'light';
@property({ type: Boolean })
clickable = false;

/**
* Color variants. Default spruce
Expand All @@ -64,18 +64,19 @@ export class Tag extends LitElement {

override render() {
const baseColorClass = `tag-${this.tagColor}`;
const shadeClass = this.shade === 'dark' ? '-dark' : '';
const sizeClass = this.tagSize === 'md' ? 'tag-medium' : 'tag-small';

const tagClasses = {
tags: true,
'tag-disable': this.disabled,
[`${baseColorClass}${shadeClass}`]: true,
'tag-clickable': this.clickable,
[`tag-clickable-${this.tagColor}`]: this.clickable,
[`${baseColorClass}`]: true,
[`${sizeClass}`]: true,
[`${sizeClass}-filter`]: this.filter,
};

const iconOutlineClasses = `${baseColorClass}${shadeClass}-close-btn`;
const iconOutlineClasses = `${baseColorClass}-close-btn`;
const iconOutlineOffsetClass = `tag-close-btn-${this.tagSize}`;
const iconClasses = {
'tag-close-btn': true,
Expand All @@ -97,21 +98,23 @@ export class Tag extends LitElement {
?disabled="${this.disabled}"
?filter=${this.filter}
tagColor=${this.tagColor}
shade=${this.shade}
title="${this.label}"
tabindex="${this.clickable ? '0' : '-1'}"
@click=${(e: any) => this.handleTagClick(e, this.label)}
@keydown=${(e: any) => this.handleTagPress(e, this.label)}
>
<span class="${classMap(labelClasses)}">${this.label}</span>
${this.filter
? html`
<button
class="${classMap(iconClasses)}"
shade=${this.shade}
?disabled="${this.disabled}"
title="${this.clearTagText}
${this.label}"
aria-label="${this.clearTagText}
${this.label}"
@click=${(e: any) => this.handleTagClear(e, this.label)}
@keydown=${(e: any) => this.handleTagClearPress(e, this.label)}
>
<span>${unsafeSVG(clearIcon16)}</span>
</button>
Expand All @@ -122,7 +125,8 @@ export class Tag extends LitElement {
}

private handleTagClear(e: any, value: string) {
if (!this.disabled) {
e.stopPropagation();
if (e.pointerType && !this.disabled) {
const event = new CustomEvent('on-close', {
detail: {
value,
Expand All @@ -132,6 +136,49 @@ export class Tag extends LitElement {
this.dispatchEvent(event);
}
}

private handleTagClearPress(e: any, value: string) {
e.stopPropagation();
// Keyboard key codes: 32 = SPACE | 13 = ENTER
if ((e.keyCode === 32 || e.keyCode === 13) && !this.disabled) {
const event = new CustomEvent('on-close', {
detail: {
value,
origEvent: e,
},
});
this.dispatchEvent(event);
}
}

private handleTagClick(e: any, value: string) {
if (!this.disabled && this.clickable) {
const event = new CustomEvent('on-click', {
detail: {
value,
origEvent: e,
},
});
this.dispatchEvent(event);
}
}

private handleTagPress(e: any, value: string) {
// Keyboard key codes: 32 = SPACE | 13 = ENTER
if (
(e.keyCode === 32 || e.keyCode === 13) &&
!this.disabled &&
this.clickable
) {
const event = new CustomEvent('on-click', {
detail: {
value,
origEvent: e,
},
});
this.dispatchEvent(event);
}
}
}

declare global {
Expand Down
24 changes: 1 addition & 23 deletions src/components/reusable/tag/tagGroup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,7 @@
gap: 4px;
}
.tag-reveal-toggle {
@include typography.type-ui-03;
padding: 0 4px 0 4px;
background: 0 0;
border: none;
color: var(--kd-color-text-link);
border-radius: 2px;
cursor: pointer;
outline: 2px solid transparent;
min-width: 72px;
margin-left: 2px;

&:hover {
color: var(--kd-color-text-link-hover);
background-color: var(--kd-color-background-accent-subtle);
}

&:active {
color: var(--kd-color-text-pressed);
}

&:focus {
outline-color: var(--kd-color-border-focus);
}
margin-left: 4px;

&-md {
height: 24px;
Expand Down
25 changes: 2 additions & 23 deletions src/components/reusable/tag/tagGroup.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,6 @@ export default {
options: ['sm', 'md'],
control: { type: 'select' },
},
shade: {
options: ['light', 'dark'],
control: { type: 'select' },
},
tagColor: {
options: [
'grey',
'spruce',
'failed',
'warning',
'passed',
'cat01',
'cat02',
'cat03',
'cat04',
'cat05',
],
control: { type: 'select' },
},
},
parameters: {
design: {
Expand All @@ -47,11 +28,10 @@ export const TagGroup = {
filter: false,
limitTags: false,
tagSize: 'md',
textStrings:{
textStrings: {
showAll: 'Show all',
showLess: 'Show less',
},
tagColor:"failed"
},
render: (args) => {
return html`
Expand Down Expand Up @@ -85,7 +65,6 @@ export const Skeleton = {
showLess: 'Show less',
},
tagSkeletonLength: 10,
shade: 'light',
},
render: (args) => {
return html`
Expand All @@ -97,7 +76,7 @@ export const Skeleton = {
>
${Array.from(
{ length: args.tagSkeletonLength },
() => html`<kyn-tag-skeleton shade=${args.shade}></kyn-tag-skeleton>`
() => html`<kyn-tag-skeleton></kyn-tag-skeleton>`
)}
</kyn-tag-group>
`;
Expand Down
8 changes: 5 additions & 3 deletions src/components/reusable/tag/tagGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { classMap } from 'lit-html/directives/class-map.js';
import './tag';
import TagGroupScss from './tagGroup.scss';
import '@kyndryl-design-system/shidoka-foundation/components/link';

/**
* Tag & Tag Group
Expand Down Expand Up @@ -64,14 +65,15 @@ export class TagGroup extends LitElement {
${this.limitTags && this.tags.length > 5
? html`
<button
<kd-link
class="${classMap(toggleBtnClasses)}"
@click=${() => this._toggleRevealed(!this.limitRevealed)}
standalone
@on-click=${() => this._toggleRevealed(!this.limitRevealed)}
>
${this.limitRevealed
? this.textStrings.showLess
: html` ${this.textStrings.showAll}`}
</button>
</kd-link>
`
: null}
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/stories/migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ _No migration effort required._
- Dropdown options
- `selected` prop has been removed. Use the `value` prop from Dropdown to control the selection.

#### Tag & Tag skeleton

- `shade` prop is removed.

#### Form Input Components

- Radio Button Group , Number Input, Text Input , Text Area, Checkbox Group, Checkbox Subgroups, Dropdown
Expand Down

0 comments on commit 1c4bf17

Please sign in to comment.