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

Heading: Add variant property #5613

Merged
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
18 changes: 18 additions & 0 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ButtonOrLinkOrTextWithChildrenProps } from "./types/button-link-text";
import { KoliBriCardEventCallbacks } from "./components/card/types";
import { EventCallbacks } from "./components/details/types";
import { KoliBriFormCallbacks } from "./components/form/types";
import { HeadingVariantPropType } from "./types/props/heading-variant";
import { Loading } from "./utils/validators/loading";
import { SuggestionsPropType } from "./types/props/suggestions";
import { InputCheckboxIconsProp, InputCheckboxVariant } from "./components/input-checkbox/types";
Expand Down Expand Up @@ -87,6 +88,7 @@ export { ButtonOrLinkOrTextWithChildrenProps } from "./types/button-link-text";
export { KoliBriCardEventCallbacks } from "./components/card/types";
export { EventCallbacks } from "./components/details/types";
export { KoliBriFormCallbacks } from "./components/form/types";
export { HeadingVariantPropType } from "./types/props/heading-variant";
export { Loading } from "./utils/validators/loading";
export { SuggestionsPropType } from "./types/props/suggestions";
export { InputCheckboxIconsProp, InputCheckboxVariant } from "./components/input-checkbox/types";
Expand Down Expand Up @@ -561,6 +563,10 @@ export namespace Components {
* Defines the text of the secondary headline.
*/
"_secondaryHeadline"?: string;
/**
* Defines which variant should be used for presentation.
*/
"_variant"?: HeadingVariantPropType;
}
interface KolHeadingWc {
/**
Expand All @@ -575,6 +581,10 @@ export namespace Components {
* Setzt den Text einer weiteren Überschrift, einen Level kleiner, unter der Ersten.
*/
"_secondaryHeadline"?: string;
/**
* Defines which variant should be used for presentation.
*/
"_variant"?: HeadingVariantPropType;
}
interface KolIcon {
/**
Expand Down Expand Up @@ -3363,6 +3373,10 @@ declare namespace LocalJSX {
* Defines the text of the secondary headline.
*/
"_secondaryHeadline"?: string;
/**
* Defines which variant should be used for presentation.
*/
"_variant"?: HeadingVariantPropType;
}
interface KolHeadingWc {
/**
Expand All @@ -3377,6 +3391,10 @@ declare namespace LocalJSX {
* Setzt den Text einer weiteren Überschrift, einen Level kleiner, unter der Ersten.
*/
"_secondaryHeadline"?: string;
/**
* Defines which variant should be used for presentation.
*/
"_variant"?: HeadingVariantPropType;
}
interface KolIcon {
/**
Expand Down
78 changes: 27 additions & 51 deletions packages/components/src/components/heading/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LabelWithExpertSlotPropType, validateLabelWithExpertSlot } from '../../
import { watchString } from '../../utils/prop.validators';
import { API, States } from './types';
import { watchHeadingLevel } from './validation';
import { HeadingVariantPropType, validateHeadingVariant } from '../../types/props/heading-variant';

/**
* @slot - Inhalt der Überschrift.
Expand All @@ -29,6 +30,11 @@ export class KolHeadingWc implements API {
*/
@Prop() public _secondaryHeadline?: string;

/**
* Defines which variant should be used for presentation.
*/
@Prop() public _variant?: HeadingVariantPropType;

@State() public state: States = {
_label: '', // ⚠ required
_level: 1,
Expand All @@ -49,64 +55,34 @@ export class KolHeadingWc implements API {
watchString(this, '_secondaryHeadline', value);
}

@Watch('_variant')
public validateVariant(value?: HeadingVariantPropType): void {
validateHeadingVariant(this, value);
}

public componentWillLoad(): void {
this.validateLabel(this._label);
this.validateLevel(this._level);
this.validateSecondaryHeadline(this._secondaryHeadline);
this.validateVariant(this._variant);
}

private readonly renderHeadline = (headline: LabelWithExpertSlotPropType, level?: number): JSX.Element => {
switch (level) {
case 1:
return (
<h1 class="headline">
{headline}
<slot name="expert" />
</h1>
);
case 2:
return (
<h2 class="headline">
{headline}
<slot name="expert" />
</h2>
);
case 3:
return (
<h3 class="headline">
{headline}
<slot name="expert" />
</h3>
);
case 4:
return (
<h4 class="headline">
{headline}
<slot name="expert" />
</h4>
);
case 5:
return (
<h5 class="headline">
{headline}
<slot name="expert" />
</h5>
);
case 6:
return (
<h6 class="headline">
{headline}
<slot name="expert" />
</h6>
);
default:
return (
<strong class="headline">
{headline}
<slot name="expert" />
</strong>
);
}
const validHeadline = typeof level === 'number' && level > 0 && level <= 6;
const HeadlineTag = validHeadline ? `h${level}` : 'strong';
const variant = this._variant || HeadlineTag;

return (
<HeadlineTag
class={{
headline: true,
[`headline-${variant}`]: true,
}}
>
{headline}
<slot name="expert" />
</HeadlineTag>
);
};

private readonly renderSecondaryHeadline = (headline: string, level?: number): JSX.Element => {
Expand Down
10 changes: 8 additions & 2 deletions packages/components/src/components/heading/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Component, h, JSX, Prop } from '@stencil/core';
import { HeadingLevel } from '../../types/heading-level';
import { LabelWithExpertSlotPropType } from '../../types/props/label';
import { Props } from './types';
import { HeadingVariantPropType } from '../../types/props/heading-variant';

/**
* @slot - Inhalt der Überschrift.
* @slot headline - Content of the headline.
*/
@Component({
tag: 'kol-heading',
Expand All @@ -17,7 +18,7 @@ import { Props } from './types';
export class KolHeading implements Props {
public render(): JSX.Element {
return (
<kol-heading-wc _label={this._label} _level={this._level} _secondaryHeadline={this._secondaryHeadline}>
<kol-heading-wc _label={this._label} _level={this._level} _secondaryHeadline={this._secondaryHeadline} _variant={this._variant}>
<slot name="expert" slot="expert" />
</kol-heading-wc>
);
Expand All @@ -37,4 +38,9 @@ export class KolHeading implements Props {
* Defines the text of the secondary headline.
*/
@Prop() public _secondaryHeadline?: string;

/**
* Defines which variant should be used for presentation.
*/
@Prop() public _variant?: HeadingVariantPropType;
}
13 changes: 0 additions & 13 deletions packages/components/src/components/heading/style.css
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
@import url(../style.css);
@layer kol-component {
:host > kol-heading-wc {
display: grid;
}

:host > kol-heading-wc > .overline {
order: 1;
}

:host > kol-heading-wc > .headline {
order: 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getHeadingWcHtml = (

return `
<kol-heading-wc${additionalAttrs}>
<${tag} class="headline">
<${tag} class="headline headline-${props._variant || tag}">
${state._label}
${slots.expert !== undefined ? slots.expert : '<slot name="expert" slot="expert"></slot>'}
</${tag}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ executeTests<Props>(
{
_label: ['Headline'],
_level: [1, 2, 3, 4, 5, 6],
_variant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong'],
// _secondaryHeadline: ['Secondary Headline'],
},
getHeadingHtml,
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/components/heading/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Generic } from '@a11y-ui/core';

import { HeadingLevel } from '../../types/heading-level';
import { PropLabelWithExpertSlot } from '../../types/props/label';
import { PropHeadingVariant } from '../../types/props/heading-variant';

type RequiredProps = PropLabelWithExpertSlot;
type OptionalProps = {
type OptionalProps = PropHeadingVariant & {
secondaryHeadline: string;
level: HeadingLevel;
};
Expand All @@ -13,7 +14,7 @@ export type Props = Generic.Element.Members<RequiredProps, OptionalProps>;
type RequiredStates = RequiredProps & {
level: HeadingLevel;
};
type OptionalStates = {
type OptionalStates = PropHeadingVariant & {
secondaryHeadline: string;
};
export type States = Generic.Element.Members<RequiredStates, OptionalStates>;
Expand Down
24 changes: 24 additions & 0 deletions packages/components/src/types/props/heading-variant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* types */
import { Generic } from '@a11y-ui/core';
import { watchValidator } from '../../utils/prop.validators';

const headingVariantPropTypeOptions = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong'] as const;
export type HeadingVariantPropType = (typeof headingVariantPropTypeOptions)[number];

/**
* Defines which variant should be used for presentation.
*/
export type PropHeadingVariant = {
variant: HeadingVariantPropType;
};

/* validator */
export const validateHeadingVariant = (component: Generic.Element.Component, value?: HeadingVariantPropType): void => {
watchValidator(
component,
`_variant`,
(value) => typeof value === 'string' && headingVariantPropTypeOptions.includes(value),
new Set([`KoliBriHeadingVariant {${headingVariantPropTypeOptions.join(', ')}`]),
value
);
};
24 changes: 12 additions & 12 deletions packages/themes/bmf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,31 +1084,31 @@ export const BMF = KoliBri.createTheme('bmf', {
}
`,
'KOL-HEADING': css`
h1,
h2,
h3,
h4,
h5,
h6 {
.headline-h1,
.headline-h2,
.headline-h3,
.headline-h4,
.headline-h5,
.headline-h6 {
color: inherit;
font-style: normal;
margin: 0;
padding: 0;
}
h1,
h2,
h3 {
.headline-h1,
.headline-h2,
.headline-h3 {
font-weight: 700;
}
h1 {
.headline-h1 {
font-size: 1.5rem;
line-height: 1.75rem;
}
h2 {
.headline-h2 {
font-size: 1.25rem;
line-height: 1.75rem;
}
h3 {
.headline-h3 {
font-size: 1.125rem;
line-height: 1.5rem;
}
Expand Down
24 changes: 12 additions & 12 deletions packages/themes/default/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,29 +992,29 @@ export const DEFAULT = KoliBri.createTheme('default', {
}
`,
'KOL-HEADING': css`
h1,
h2,
h3,
h4,
h5,
h6 {
.headline-h1,
.headline-h2,
.headline-h3,
.headline-h4,
.headline-h5,
.headline-h6 {
color: inherit;
font-style: normal;
}
h1,
h2,
h3 {
.headline-h1,
.headline-h2,
.headline-h3 {
font-weight: 700;
}
h1 {
.headline-h1 {
font-size: 1.5rem;
line-height: 1.75rem;
}
h2 {
.headline-h2 {
font-size: 1.25rem;
line-height: 1.75rem;
}
h3 {
.headline-h3 {
font-size: 1.125rem;
line-height: 1.5rem;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/themes/ecl/src/ecl-ec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ export const ECL_EC = KoliBri.createTheme('ecl-ec', {
}
`,
'KOL-HEADING': css`
h1 {
.headline-h1 {
font-size: 2rem;
line-height: 2.5rem;
}
h2 {
.headline-h2 {
font-size: 1.75rem;
line-height: 2rem;
}
h3 {
.headline-h3 {
font-size: 1.5rem;
line-height: 1.75rem;
}
h4 {
.headline-h4 {
font-size: 1.25rem;
line-height: 1.75rem;
}
h5 {
.headline-h5 {
font-size: 1rem;
line-height: 1.5rem;
}
h6 {
.headline-h6 {
color: rgb(234, 0, 255);
}
`,
Expand Down
Loading
Loading