Skip to content

Commit

Permalink
Select fix (#214)
Browse files Browse the repository at this point in the history
* fix(tokens): brand becomes Brand

* refactor(tokens): updates token name

* feat(tokens): adds MD and LG paddings

* feat(tokens): adds LG tokens

* feat(ui-library): select is back

* feat(ui-library): renderfunction for icons

* fix(ui-library): snapshot

---------

Co-authored-by: christian.b.hoffmann <christian.b.hoffmann@accenture.com>
  • Loading branch information
m-nti and ChristianHoffmannS2 authored Jun 12, 2023
1 parent cc682f2 commit ded4de5
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 13 deletions.
22 changes: 21 additions & 1 deletion packages/figma-design-tokens/input/tokens/semantics/BLR_CMP.json
Original file line number Diff line number Diff line change
Expand Up @@ -2084,14 +2084,34 @@
},
"Select": {
"SM": {
"InputPadding": {
"InputFieldPadding": {
"value": "{core.dimensionREM.8} {core.dimensionPX.32} {core.dimensionREM.8} {core.dimensionPX.12}",
"type": "spacing"
},
"IconPaddingRight": {
"value": "{core.dimensionPX.12}",
"type": "spacing"
}
},
"MD": {
"InputFieldPadding": {
"value": "{core.dimensionREM.8} {core.dimensionPX.32} {core.dimensionREM.8} {core.dimensionPX.12}",
"type": "spacing"
},
"IconPaddingRight": {
"value": "{core.dimensionPX.12}",
"type": "spacing"
}
},
"LG": {
"InputFieldPadding": {
"value": "{core.dimensionREM.12} {core.dimensionPX.48} {core.dimensionREM.12} {core.dimensionPX.16}",
"type": "spacing"
},
"IconPaddingRight": {
"value": "{core.dimensionPX.16}",
"type": "spacing"
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@
"type": "color"
}
},
"brand": {
"Brand": {
"Default": {
"Shape": {
"Background": {
Expand Down
26 changes: 17 additions & 9 deletions packages/ui-library/src/components/icon/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { html } from 'lit-html';
import { IconKeys } from '@boiler/icons';

import './index';
import { BlrIcon as BlrIconClass } from './index';
import { BlrIcon as BlrIconClass, BlrIconRenderFunction } from './index';
import { Sizes } from '../../globals/constants';
import { getIconName } from '../../utils/get-icon-name';
import { calculateIconName } from '../../utils/calculate-icon-name';
import { classMap } from 'lit/directives/class-map.js';

export default {
title: 'BlrIcon',
Expand All @@ -15,25 +16,32 @@ export default {
control: { type: 'select' },
},
},
parameters: {
previewTabs: {
canvas: { hidden: true },
},
viewMode: 'docs',
},
};

const allIcons = getIconName(IconKeys);

export const BlrIcon = ({ size }: BlrIconClass) =>
html` <div class="icon-gallery row-fluid">
export const BlrIcon = ({ size }: BlrIconClass) => {
const classes = classMap({
'icon-gallery-layout': true,
});

return html`<div class="icon-gallery row-fluid">
<ul class="icon-gallery icon-thumbnails">
${allIcons.map((icon) => {
return html` <li>
<blr-icon
icon="${calculateIconName(icon as string, size)}"
size="${size}"
class="icon-gallery-layout"
></blr-icon>
return html`<li>
${BlrIconRenderFunction({ icon: calculateIconName(icon as string, size), size: size, classMap: classes })}
<span class="icon-label">${icon}</span>
</li>`;
})}
</ul>
</div>`;
};

BlrIcon.storyName = 'BlrIcon';

Expand Down
36 changes: 34 additions & 2 deletions packages/ui-library/src/components/icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { LitElement, html, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { IconMapping, IconType } from '@boiler/icons';
import { icon } from '../../foundation/component-tokens/ui.css';
// import { Sizes } from '../../globals/constants';
import { styleCustom } from './index.css';
import { SizesType } from '../../globals/types';
import { DirectiveResult } from 'lit-html/directive';
import { ClassMapDirective } from 'lit-html/directives/class-map';
import { styleMap } from 'lit/directives/style-map.js';

@customElement('blr-icon')
export class BlrIcon extends LitElement {
Expand All @@ -13,11 +15,41 @@ export class BlrIcon extends LitElement {
@property() icon!: IconType;
@property() size!: SizesType;

render() {
protected render() {
if (IconMapping.hasOwnProperty(this.icon) && typeof IconMapping[this.icon] === 'function') {
return html`${IconMapping[this.icon](`blr-icon ${this.size.toLowerCase()}`)}`;
} else {
return nothing;
}
}
}

// BlrIconType is a new Type containing all properties of BlrIcon without the properties of LitElement
// and some additional properties which are not part of the component
export type BlrIconType = Partial<Omit<BlrIcon, keyof LitElement>> & {
classMap?: DirectiveResult<typeof ClassMapDirective>;
onClick?: HTMLElement['onclick'];
hideAria?: boolean;
name?: string;
disablePointerEvents?: boolean;
};

export const BlrIconRenderFunction = ({
icon,
size,
classMap,
onClick,
hideAria,
name,
disablePointerEvents,
}: BlrIconType) => {
return html`<blr-icon
class="blr-input-icon ${classMap}"
.icon=${icon || nothing}
.size=${size}
.name=${name || nothing}
aria-hidden=${hideAria || nothing}
@click=${onClick}
style=${disablePointerEvents ? styleMap({ pointerEvents: 'none' }) : nothing}
></blr-icon>`;
};
16 changes: 16 additions & 0 deletions packages/ui-library/src/components/select/index.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { css } from 'lit';

export const styleCustom = css`
.blr-select {
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
}
.blr-select-option {
display: flex;
flex-direction: column;
align-items: flex-start;
}
`;
108 changes: 108 additions & 0 deletions packages/ui-library/src/components/select/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* eslint-disable no-console */
import { html } from 'lit-html';
import { BlrSelectRenderFunction, BlrSelectType } from './index';
import { FormSizes } from '../../globals/constants';
import { IconKeys } from '@boiler/icons';
import { getIconName } from '../../utils/get-icon-name';
import './index';

export default {
title: 'BlrSelect',
argTypes: {
size: {
options: FormSizes,
control: { type: 'select' },
},
trailingIcon: {
options: [...getIconName(IconKeys)],
control: { type: 'select' },
},
hintIcon: {
options: [...getIconName(IconKeys)],
control: { type: 'select' },
},
options: {
control: 'array',
options: [
{ value: 'uschi', label: 'Uschi', selected: false, disabled: false },
{ value: '1', label: 'Option 1', selected: false, disabled: false },
{ value: '2', label: 'Option 2', selected: true, disabled: false },
{ value: 'dieter', label: 'Dieter', selected: true, disabled: false },
],
},
onChange: {
action: 'onChange',
description: '(@change)="onChange($event)"',
},
},
parameters: {
previewTabs: {
canvas: { hidden: true },
},
viewMode: 'docs',
},
};

export const BlrSelect = ({
selectId,
onChange,
name,
options,
disabled,
size,
required,
errorMessage,
hint,
hintIcon,
hasError,
labelAppendix,
showTrailingIcon,
trailingIcon,
hasLabel,
label,
}: BlrSelectType) =>
html`
${BlrSelectRenderFunction({
selectId,
onChange,
name,
options,
disabled,
size,
required,
errorMessage,
hint,
hintIcon,
hasError,
labelAppendix,
showTrailingIcon,
trailingIcon,
hasLabel,
label,
})}
`;

BlrSelect.storyName = 'BlrSelect';

BlrSelect.args = {
name: 'Text Input',
hasLabel: true,
label: 'Label',
labelAppendix: '(Optional)',
showTrailingIcon: true,
size: 'md',
hasError: false,
errorMessage: 'This is error message',
disabled: false,
required: false,
hint: 'Field is used for hint',
hintIcon: 'blrInfo',
selectId: 'Peter',
trailingIcon: 'blr360',
options: [
{ value: 'uschi', label: 'Uschi', disabled: true },
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2', selected: true },
{ value: 'dieter', label: 'Dieter' },
],
};
Loading

0 comments on commit ded4de5

Please sign in to comment.