Skip to content

Commit

Permalink
[@next][badge] refactor to use design tokens (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
DRiFTy17 authored Feb 1, 2024
1 parent 204c77d commit ba9d7a1
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 432 deletions.
53 changes: 35 additions & 18 deletions src/dev/pages/badge/badge.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,57 @@
</div>

<div class="vert">
<forge-icon-button class="forge-icon-button--with-badge">
<forge-icon name="notifications" external></forge-icon>
<forge-badge dot positioned></forge-badge>
<forge-badge>
<forge-icon name="heart" slot="start"></forge-icon>
w/Start icon
</forge-badge>
<forge-badge>
w/End icon
<forge-icon name="heart" slot="end"></forge-icon>
</forge-badge>
</div>

<div class="flex">
<forge-icon-button>
<forge-icon name="notifications"></forge-icon>
<forge-badge slot="badge" dot></forge-badge>
</forge-icon-button>

<forge-icon-button class="forge-icon-button--with-badge">
<forge-icon name="notifications" external></forge-icon>
<forge-badge positioned>99</forge-badge>
<forge-icon-button>
<forge-icon name="notifications"></forge-icon>
<forge-badge slot="badge">99</forge-badge>
</forge-icon-button>

<forge-icon-button class="forge-icon-button--with-badge">
<forge-icon name="notifications" external></forge-icon>
<forge-badge positioned>999999+</forge-badge>
<forge-icon-button>
<forge-icon name="notifications"></forge-icon>
<forge-badge slot="badge">999999+</forge-badge>
</forge-icon-button>
</div>

<div class="flex">
<div class="vert">
<h3 class="forge-typography--heading2">Theme</h3>
<forge-badge>Default</forge-badge>
<forge-badge theme="danger">Danger</forge-badge>
<forge-badge theme="warning">Warning</forge-badge>
<forge-badge theme="primary">Primary</forge-badge>
<forge-badge theme="secondary">Secondary</forge-badge>
<forge-badge theme="tertiary">Tertiary</forge-badge>
<forge-badge theme="success">Success</forge-badge>
<forge-badge theme="info-primary">Info (primary)</forge-badge>
<forge-badge theme="error">Error</forge-badge>
<forge-badge theme="warning">Warning</forge-badge>
<forge-badge theme="info">Info</forge-badge>
<forge-badge theme="info-secondary">Info (secondary)</forge-badge>
</div>
<div class="vert">
<h3 class="forge-typography--heading2">Strong theme</h3>
<h3 class="forge-typography--heading2">Theme (strong)</h3>
<forge-badge strong>Default</forge-badge>
<forge-badge theme="danger" strong>Danger</forge-badge>
<forge-badge theme="warning" strong>Warning</forge-badge>
<forge-badge theme="success" strong>Success</forge-badge>
<forge-badge theme="info-primary" strong>Info (primary)</forge-badge>
<forge-badge theme="info-secondary" strong>Info (secondary)</forge-badge>
<forge-badge strong theme="primary">Primary</forge-badge>
<forge-badge strong theme="secondary">Secondary</forge-badge>
<forge-badge strong theme="tertiary">Tertiary</forge-badge>
<forge-badge strong theme="success">Success</forge-badge>
<forge-badge strong theme="error">Error</forge-badge>
<forge-badge strong theme="warning">Warning</forge-badge>
<forge-badge strong theme="info">Info</forge-badge>
<forge-badge strong theme="info-secondary">Info (secondary)</forge-badge>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/dev/pages/badge/badge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import '$src/shared';
import '@tylertech/forge/badge';
import '@tylertech/forge/icon-button';
import { tylIconNotifications } from '@tylertech/tyler-icons/standard';
import { IconRegistry } from '@tylertech/forge/icon';
import { tylIconHeart } from '@tylertech/tyler-icons/extended';

IconRegistry.define([tylIconHeart, tylIconNotifications]);
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ export class AppBarNotificationButtonAdapter extends BaseAdapter<IAppBarNotifica
}

public setBadgeVisible(isVisible: boolean): void {
this._badgeElement.open = isVisible;
this._badgeElement.hide = !isVisible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('App Bar Notification Button', () => {
const badgeEl = el.querySelector('forge-badge') as IBadgeComponent;

expect(badgeEl).to.be.ok;
expect(badgeEl.open).to.be.true;
expect(badgeEl.hide).to.be.false;
expect(badgeEl.innerText).to.equal('0');
});

Expand All @@ -78,7 +78,7 @@ describe('App Bar Notification Button', () => {
el.showBadge = true;

expect(badgeEl).to.be.ok;
expect(badgeEl.open).to.be.true;
expect(badgeEl.hide).to.be.false;
expect(badgeEl.innerText).to.equal('0');
});

Expand All @@ -89,7 +89,7 @@ describe('App Bar Notification Button', () => {

const badgeEl = el.querySelector('forge-badge') as IBadgeComponent;
expect(badgeEl).to.be.ok;
expect(badgeEl.open).to.be.false;
expect(badgeEl.hide).to.be.true;
});

it('should show badge with count', async () => {
Expand Down
53 changes: 53 additions & 0 deletions src/lib/badge/_core.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@use './token-utils' as *;
@use '../core/styles/typography';

@forward './token-utils';

@mixin host {
display: flex;
box-sizing: border-box;
}

@mixin base {
@include typography.style(label);

background: #{token(background)};
color: #{token(color)};

height: #{token(height)};
min-width: #{token(min-width)};
max-width: #{token(max-width)};

border-width: #{token(border-width)};
border-style: #{token(border-style)};
border-color: #{token(border-color)};

display: inline-flex;
align-items: center;
gap: #{token(gap)};
border-radius: #{token(shape)};
padding-inline: #{token(padding-inline)};
padding-block: #{token(padding-block)};
overflow: hidden;
box-sizing: border-box;

pointer-events: none;

transition: transform #{token(transition-duration)} #{token(transition-easing)};

font-weight: #{token(font-weight)};
text-overflow: ellipsis;
white-space: nowrap;
}

@mixin dot {
@include override(height, dot-height);
@include override(min-width, auto, value);

padding: #{token(dot-padding)};
width: #{token(dot-width)};
}

@mixin hide {
transform: scale(0);
}
25 changes: 25 additions & 0 deletions src/lib/badge/_token-utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@use '../core/styles/tokens/badge/tokens';
@use '../core/styles/tokens/token-utils';

$_module: badge;
$_tokens: tokens.$tokens;

@mixin provide-theme($theme) {
@include token-utils.provide-theme($_module, $_tokens, $theme);
}

@function token($name, $type: token) {
@return token-utils.token($_module, $_tokens, $name, $type);
}

@function declare($token) {
@return token-utils.declare($_module, $token);
}

@mixin override($token, $token-or-value, $type: token) {
@include token-utils.override($_module, $_tokens, $token, $token-or-value, $type);
}

@mixin tokens($includes: null, $excludes: null) {
@include token-utils.tokens($_module, $_tokens, $includes, $excludes);
}
26 changes: 0 additions & 26 deletions src/lib/badge/badge-adapter.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/lib/badge/badge-component-delegate.ts

This file was deleted.

16 changes: 11 additions & 5 deletions src/lib/badge/badge-constants.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { COMPONENT_NAME_PREFIX } from '../constants';
import { COMPONENT_NAME_PREFIX, Theme } from '../constants';

const elementName: keyof HTMLElementTagNameMap = `${COMPONENT_NAME_PREFIX}badge`;

const attributes = {
DOT: 'dot',
OPEN: 'open',
HIDE: 'hide',
THEME: 'theme',
STRONG: 'strong'
};

const classes = {
DOT: 'forge-badge--dot',
OPEN: 'forge-badge--open'
OPEN: 'open'
};

const selectors = {
ROOT: '.forge-badge'
};

const defaults = {
THEME: 'default' as BadgeTheme
};

export const BADGE_CONSTANTS = {
elementName,
attributes,
selectors,
classes,
selectors
defaults
};

export type BadgeTheme = Theme | 'default' | 'info-primary' | 'info-secondary' | 'danger';
61 changes: 0 additions & 61 deletions src/lib/badge/badge-foundation.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/lib/badge/badge.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="forge-badge forge-badge--open" part="root">
<slot name="leading"></slot>
<div class="forge-badge" part="root">
<slot name="start"></slot>
<slot></slot>
<slot name="trailing"></slot>
<slot name="end"></slot>
</div>
</template>
Loading

0 comments on commit ba9d7a1

Please sign in to comment.