Skip to content

Commit

Permalink
badge refactor
Browse files Browse the repository at this point in the history
Refs: #7036
  • Loading branch information
AlexanderSchmidtCE committed Nov 16, 2024
1 parent 378b0cc commit 0a240ac
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 111 deletions.
29 changes: 14 additions & 15 deletions packages/components/src/components/badge/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { BadgeAPI, BadgeStates, ButtonProps, KoliBriIconsProp, LabelPropType, PropColor, Stringified } from '../../schema';
import { featureHint, handleColorChange, objectObjectHandler, parseJson, setState, validateColor } from '../../schema';
import { Component, h, Host, Prop, State, Watch } from '@stencil/core';
import { Component, h, Prop, State, Watch } from '@stencil/core';
import { KolSpanWcTag } from '../../core/component-names';

import { nonce } from '../../utils/dev.utils';

import type { JSX } from '@stencil/core';
import { KolButtonWcTag } from '../../core/component-names';
import clsx from 'clsx';
featureHint(`[KolBadge] Optimierung des _color-Properties (rgba, rgb, hex usw.).`);

@Component({
Expand Down Expand Up @@ -41,20 +42,18 @@ export class KolBadge implements BadgeAPI {
public render(): JSX.Element {
const hasSmartButton = typeof this.state._smartButton === 'object' && this.state._smartButton !== null;
return (
<Host class="kol-badge">
<span
class={{
'smart-button': typeof this.state._smartButton === 'object' && this.state._smartButton !== null,
}}
style={{
backgroundColor: this.bgColorStr,
color: this.colorStr,
}}
>
<KolSpanWcTag id={hasSmartButton ? this.id : undefined} _allowMarkdown _icons={this._icons} _label={this._label}></KolSpanWcTag>
{hasSmartButton && this.renderSmartButton(this.state._smartButton as ButtonProps)}
</span>
</Host>
<span
class={clsx('kol-badge', {
'smart-button': typeof this.state._smartButton === 'object' && this.state._smartButton !== null,
})}
style={{
backgroundColor: this.bgColorStr,
color: this.colorStr,
}}
>
<KolSpanWcTag id={hasSmartButton ? this.id : undefined} _allowMarkdown _icons={this._icons} _label={this._label}></KolSpanWcTag>
{hasSmartButton && this.renderSmartButton(this.state._smartButton as ButtonProps)}
</span>
);
}

Expand Down
16 changes: 7 additions & 9 deletions packages/components/src/components/badge/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
@import '../style';

@layer kol-component {
/* :host implicitly inherits font-size, e.g. for usage in headlines */
:host {
font-size: rem(16);
}

:host > span {
.kol-badge {
display: inline-flex;
place-items: center;
/* Visible with forced colors */
outline: transparent solid rem(1);
}
font-size: rem(16);

:host > span > .kol-button-wc button {
color: inherit;
.kol-button-wc {
button {
color: inherit;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`kol-badge should render with _label="**Te**xt" 1`] = `
<kol-badge class="kol-badge">
<kol-badge>
<template shadowrootmode="open">
<span style="background-color: #000; color: #959595;">
<span class="kol-badge" style="background-color: #000; color: #959595;">
<kol-span-wc _allowmarkdown="" _label="**Te**xt"></kol-span-wc>
</span>
</template>
</kol-badge>
`;

exports[`kol-badge should render with _label="Text" _color="#000000" 1`] = `
<kol-badge class="kol-badge">
<kol-badge>
<template shadowrootmode="open">
<span style="background-color: #000; color: #959595;">
<span class="kol-badge" style="background-color: #000; color: #959595;">
<kol-span-wc _allowmarkdown="" _label="Text"></kol-span-wc>
</span>
</template>
</kol-badge>
`;

exports[`kol-badge should render with _label="Text" _icons="codicon codicon-home" _color="#000000" 1`] = `
<kol-badge class="kol-badge">
<kol-badge>
<template shadowrootmode="open">
<span style="background-color: #000; color: #959595;">
<span class="kol-badge" style="background-color: #000; color: #959595;">
<kol-span-wc _allowmarkdown="" _icons="codicon codicon-home" _label="Text"></kol-span-wc>
</span>
</template>
</kol-badge>
`;

exports[`kol-badge should render with _label="Text" _icons="codicon codicon-home" 1`] = `
<kol-badge class="kol-badge">
<kol-badge>
<template shadowrootmode="open">
<span style="background-color: #000; color: #959595;">
<span class="kol-badge" style="background-color: #000; color: #959595;">
<kol-span-wc _allowmarkdown="" _icons="codicon codicon-home" _label="Text"></kol-span-wc>
</span>
</template>
</kol-badge>
`;

exports[`kol-badge should render with _label="Text" 1`] = `
<kol-badge class="kol-badge">
<kol-badge>
<template shadowrootmode="open">
<span style="background-color: #000; color: #959595;">
<span class="kol-badge" style="background-color: #000; color: #959595;">
<kol-span-wc _allowmarkdown="" _label="Text"></kol-span-wc>
</span>
</template>
Expand Down
16 changes: 6 additions & 10 deletions packages/themes/bmf/src/components/badge.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
@import '../mixins/rem';

@layer kol-theme-component {
:host {
display: inline-block;
font-family: var(--font-family);
}

:host .kol-icon {
color: inherit;
}

:host > span {
.kol-badge {
border-radius: rem(5);
display: inline-flex;
font-family: var(--font-family);
font-style: normal;

.kol-icon {
color: inherit;
}

.kol-span-wc {
padding: rem(4) rem(12);
}
Expand Down
63 changes: 28 additions & 35 deletions packages/themes/default/src/components/badge.scss
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
@import '../mixins/rem';

@layer kol-theme-component {
:host {
display: inline-block;
.kol-badge {
font-family: var(--font-family);
}

:host > span {
border-radius: var(--border-radius);
display: inline-flex;
font-style: normal;
}

:host > span.smart-button {
align-items: center;
}

:host > span .kol-button-wc:hover > button {
background-color: var(--color-primary-variant);
color: var(--color-light);
}

:host > span .kol-button-wc > button {
color: inherit;
border-top-right-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
padding: rem(3.2);
}

:host > span .kol-span-wc {
padding: rem(4) rem(12);
}

:host > span > .kol-span-wc {
align-items: center;
font-style: normal;
gap: rem(8);
}

:host > span > .kol-span-wc > span {
display: flex;
gap: rem(4);
span.smart-button {
align-items: center;
}

.kol-button-wc:hover > button {
background-color: var(--color-primary-variant);
color: var(--color-light);
}

.kol-button-wc > button {
color: inherit;
border-top-right-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
padding: rem(3.2);
}

.kol-span-wc {
padding: rem(4) rem(12);
align-items: center;
font-style: normal;
gap: rem(8);

span {
display: flex;
gap: rem(4);
}
}
}
}
2 changes: 1 addition & 1 deletion packages/themes/ecl/src/ecl-ec/components/badge.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import '../../mixins/rem';

@layer kol-theme-component {
:host > span {
.kol-badge {
font: normal normal var(--font-weight) 1em var(--font-family);
padding: calc(rem(8) - rem(1)) calc(rem(12) - rem(1));
text-transform: uppercase;
Expand Down
7 changes: 2 additions & 5 deletions packages/themes/ecl/src/ecl-eu/components/badge.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@import '../../mixins/rem';

@layer kol-theme-component {
:host {
font-family: var(--font-family);
}

:host > span {
.kol-badge {
font: normal normal var(--font-weight) rem(14) / 1em var(--font-family);
font-family: var(--font-family);
padding: calc(rem(8) - rem(1)) calc(rem(12) - rem(1));
text-transform: uppercase;
}
Expand Down
44 changes: 18 additions & 26 deletions packages/themes/itzbund/src/components/badge.scss
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
@import '../mixins/rem';

@layer kol-theme-component {
:host {
display: inline-block;
.kol-badge {
display: inline-flex;
font-family: inherit;
}

:host > span {
border-radius: rem(5);
display: inline-flex;
}

:host > span .kol-button-wc {
border-left: rem(1) solid rgba(0, 0, 0, 0.25);
}
.kol-button-wc {
border-left: rem(1) solid rgba(0, 0, 0, 0.25);
}
.kol-span-wc {
align-items: center;
font-style: normal;
gap: rem(8);
padding: rem(4) rem(8);

:host > span .kol-span-wc {
padding: rem(4) rem(8);
}

:host > span > .kol-span-wc {
align-items: center;
font-style: normal;
gap: rem(8);
}

:host > span > .kol-span-wc > span {
display: flex;
gap: rem(4);
}
span {
display: flex;
gap: rem(4);
}
}

:host button {
border-radius: 0 var(--spacing) var(--spacing) 0;
button {
border-radius: 0 var(--spacing) var(--spacing) 0;
}
}
}

0 comments on commit 0a240ac

Please sign in to comment.