Skip to content

Commit 2a49009

Browse files
author
Lukas Gundermann
committed
Enhance BlnButton component and stories: implement new retroDesign property, introduce additional variants, and update styles with Tailwind CSS refinements. Refactor BlnHeader to include BlnButton and apply shadow-header class.
1 parent 92b18ac commit 2a49009

7 files changed

Lines changed: 160 additions & 85 deletions

File tree

src/components/BlnButton.stories.ts

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const meta = {
2121
?disabled=${args.disabled === true}
2222
?with-stripes=${ifDefined(args.withStripes)}
2323
${args.withArrow ? 'with-arrow' : ''}
24+
retro-design=${ifDefined(args.retroDesign)}
2425
.onClick=${args.onClick}
2526
>${ifDefined(args.label)}
2627
</bln-button>`,
@@ -29,11 +30,12 @@ const meta = {
2930
class: {description: 'Additional CSS classes to apply to the button', type: {name: 'string'}},
3031
withArrow: {control: 'boolean', description: 'Whether to show an arrow icon', type: {name: 'boolean'}},
3132
withStripes: {control: 'boolean', description: 'Whether to show stripes', type: {name: 'boolean'}},
33+
retroDesign: {control: 'boolean', description: 'Whether to use the retro design', type: {name: 'boolean'}},
3234
variant: {
3335
description: 'Variant of the button',
3436
type: {name: 'string'},
3537
control: {type: 'select'},
36-
options: ['primary', 'link', 'secondary'],
38+
options: ['solid', 'link', 'outline', 'ghost', 'soft'],
3739
},
3840
size: {
3941
description: 'Size of the button',
@@ -42,43 +44,100 @@ const meta = {
4244
options: ['small', 'medium', 'large'],
4345
},
4446
},
45-
args: {label: 'BlnButton', onClick: fn()},
47+
args: {label: 'Button', onClick: fn()},
4648
} satisfies Meta<BlnButtonProps>;
4749

4850
export default meta;
4951
type Story = StoryObj<BlnButtonProps>;
5052

5153
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
52-
export const Primary: Story = {
54+
export const Solid: Story = {
5355
args: {
54-
label: 'BlnButton',
56+
variant: 'solid',
5557
},
5658
};
5759

58-
export const PrimaryArrow: Story = {
60+
export const Outline: Story = {
5961
args: {
60-
withArrow: true,
61-
label: 'BlnButton',
62+
variant: 'outline',
6263
},
6364
};
6465

65-
export const PrimaryStripes: Story = {
66+
export const Ghost: Story = {
6667
args: {
67-
withStripes: true,
68-
label: 'BlnButton',
68+
variant: 'ghost',
69+
},
70+
};
71+
72+
export const Soft: Story = {
73+
args: {
74+
variant: 'soft',
6975
},
7076
};
7177

7278
export const Link: Story = {
7379
args: {
74-
label: 'BlnButton',
7580
variant: 'link',
7681
},
7782
};
7883

84+
export const Arrow: Story = {
85+
args: {
86+
variant: 'arrow',
87+
},
88+
};
89+
90+
export const ArrowRed: Story = {
91+
args: {
92+
variant: 'arrow-red',
93+
},
94+
};
95+
96+
export const Retro: Story = {
97+
args: {
98+
retroDesign: true,
99+
},
100+
};
101+
102+
export const RetroLink: Story = {
103+
args: {
104+
variant: 'link',
105+
retroDesign: true,
106+
},
107+
};
108+
109+
export const RetroArrow: Story = {
110+
args: {
111+
variant: 'arrow',
112+
retroDesign: true,
113+
},
114+
};
115+
116+
export const RetroArrowRed: Story = {
117+
args: {
118+
variant: 'arrow-red',
119+
retroDesign: true,
120+
},
121+
};
122+
123+
export const Stripes: Story = {
124+
args: {
125+
withStripes: true,
126+
variant: 'solid',
127+
retroDesign: true,
128+
size: 'small'
129+
},
130+
};
131+
79132
export const Disabled: Story = {
80133
args: {
81-
label: 'BlnButton',
82134
disabled: true,
83135
},
136+
};
137+
138+
export const DisabledRetro: Story = {
139+
args: {
140+
disabled: true,
141+
retroDesign: true,
142+
},
84143
};

src/components/BlnButton.ts

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ import {html, LitElement, PropertyValues} from "lit";
33
import tailwindCss from '../styles/tailwind.min.css?raw';
44
import TailwindElement from "../app/TailwindElement";
55

6+
import './LucideIcon';
7+
68
export interface BlnButtonProps {
7-
variant?: 'primary' | 'link';
9+
variant?: 'solid' | 'outline' | 'ghost' | 'soft' | 'link' | 'arrow' | 'arrow-red';
810
withArrow: boolean,
911
withStripes: boolean,
1012
size?: 'small' | 'medium' | 'large';
1113
label: string;
1214
onClick?: () => void;
1315
disabled?: boolean;
1416
class?: string;
17+
retroDesign: boolean;
1518
}
1619

1720
@customElement('bln-button')
1821
export class BlnButton extends TailwindElement {
19-
// Cache für geladene Tailwind-CSS (einmal pro Seite)
20-
2122
/**
2223
* Represents an HTML button element type.
2324
*
@@ -43,17 +44,14 @@ export class BlnButton extends TailwindElement {
4344
*
4445
* Possible value: "primary"
4546
*/
46-
@property({type: String}) variant = "primary";
47+
@property({type: String}) variant = "solid";
4748

4849

4950
/**
50-
* Represents the size of an object or entity.
51-
*
52-
* This variable is typically used to define or adjust configurations,
53-
* properties, or appearances where size is a consideration.
54-
*
55-
* Possible values may include descriptive size terms such as
56-
* "small", "medium", "large", or custom definitions based on context.
51+
* Represents the size of an item or element.
52+
* This variable holds a string value indicating the size classification.
53+
* Commonly used to define or adjust dimensions, layouts, or options.
54+
* Possible values might include "small", "medium", "large", etc.
5755
*/
5856
@property({type: String}) size = "medium";
5957

@@ -74,13 +72,10 @@ export class BlnButton extends TailwindElement {
7472
*/
7573
@property({type: Boolean, reflect: true}) disabled = false;
7674

77-
7875
/**
7976
* This variable indicates whether a striped effect is applied or not.
8077
* It is a boolean value that defaults to false, implying that the striped effect
8178
* is disabled unless explicitly set to true.
82-
*
83-
* @type {boolean}
8479
*/
8580
@property({type: Boolean, attribute: "with-stripes"}) withStripes = false;
8681

@@ -100,71 +95,80 @@ export class BlnButton extends TailwindElement {
10095
*/
10196
@property({attribute: false}) onClick?: (e: MouseEvent) => void;
10297

103-
protected firstUpdated(_changedProperties: PropertyValues) {
104-
super.firstUpdated(_changedProperties);
105-
106-
}
107-
108-
109-
110-
11198
/**
11299
* Renders a button with customizable styles and behaviors based on properties such as size, variant, arrow inclusion, and disabled state.
113100
* The method dynamically constructs the button's classes, applies relevant styles, and optionally renders a right arrow icon based on button configuration.
114101
*/
115102
renderButton() {
116-
// Button types
117-
const isLink = this.variant === 'link';
118-
119-
// Classes
120-
const base = isLink
121-
? "border-2 border-[#e40422] bg-white font-bold"
122-
: "border-2 border-black bg-white";
123-
const size = this.size === 'small' ? 'text-sm' : this.size === 'large' ? 'text-lg' : '';
124-
const padding = isLink
125-
? this.size === 'small'
126-
? 'py-2 px-3'
127-
: 'py-3 px-4'
128-
: this.withArrow
129-
? ''
130-
: this.size === 'small'
131-
? 'py-1 px-3'
132-
: 'py-2 px-5';
133-
const hover = !this.disabled && !isLink ? 'hover:bg-gray-200' : isLink ? 'hover:underline' : '';
134-
const disabled = this.disabled ? 'opacity-50 cursor-not-allowed' : '';
135-
const spanClasses = this.withArrow
136-
? this.size === 'small'
137-
? 'py-1 px-3 border-r-2 border-black'
138-
: 'py-2 px-5 border-r-2 border-black'
139-
: '';
140-
const buttonClasses = [
141-
'transition duration-700 flex items-stretch',
142-
base,
143-
disabled,
144-
size,
145-
padding,
146-
hover,
147-
this.class, // zusätzliche Host-übergebene Klassen
148-
].filter(Boolean).join(' ');
149-
150-
const arrayBGColor = this.variant === 'secondary' ? "black" : "#e40422";
151-
152-
// Render
153103
return html`
154-
<!-- Tailwind aus Storybook Static Dir -->
155-
<!-- <link rel="stylesheet" href="/tailwind.css"/>-->
156-
157-
<button class="${buttonClasses}"
104+
<button class="${this.cn(
105+
'transition duration-700 disabled:pointer-events-none',
106+
[
107+
this.retroDesign
108+
? 'inline-flex border-2 font-semibold border-black bg-white hover:bg-gray-200'
109+
: 'inline-flex items-center gap-x-2 text-sm font-medium rounded border focus:outline-hidden',
110+
this.disabled
111+
? 'disabled:cursor-not-allowed disabled:opacity-50'
112+
: '',
113+
(this.variant === 'solid' || this.variant === null) && !this.retroDesign
114+
? 'bg-blue-500 text-white hover:bg-blue-600 focus:bg-blue-600 border-transparent'
115+
: '',
116+
this.variant === 'outline' && !this.retroDesign
117+
? 'border-gray-200 text-gray-500 hover:border-blue-600 hover:text-blue-600 focus:border-blue-600 focus:text-blue-600'
118+
: '',
119+
this.variant === 'ghost' && !this.retroDesign
120+
? 'border-transparent text-blue-500 hover:bg-blue-100 hover:text-blue-800 focus:bg-blue-100 focus:text-blue-800'
121+
: '',
122+
this.variant === 'soft' && !this.retroDesign
123+
? 'border-transparent bg-blue-100 text-blue-800 hover:bg-blue-200 focus:bg-blue-200'
124+
: '',
125+
this.variant === 'link'
126+
? this.retroDesign
127+
? 'border-2 !border-[#e40422] bg-white font-bold hover:!bg-transparent hover:underline'
128+
: 'border-transparent text-blue-500 hover:text-blue-700 focus:text-blue-700'
129+
: '',
130+
(this.variant === 'arrow' || this.variant === 'arrow-red') && !this.retroDesign
131+
? 'border-transparent hover:text-gray-400 transition duration-700'
132+
: ''
133+
]
134+
)}"
158135
?disabled=${this.disabled}
159136
@click=${(e: MouseEvent) => this.onClick?.(e)}>
160-
<span class="${spanClasses}"><slot></slot></span>
161-
${this.withArrow
137+
<span class="${this.cn([
138+
this.size === 'large'
139+
? 'p-4 sm:p-5'
140+
: this.size === 'small'
141+
? 'py-2 px-3'
142+
: 'py-3 px-4',
143+
this.variant === 'arrow' || this.variant === 'arrow-red'
144+
? this.retroDesign
145+
? 'border-r-2 border-black'
146+
: 'pr-1'
147+
: '',
148+
this.retroDesign
149+
? ''
150+
: 'border-transparent',
151+
])}"><slot></slot></span>
152+
${this.variant === 'arrow' || this.variant === 'arrow-red'
162153
? html`
163-
<div class="px-3 flex items-center" style="background: ${arrayBGColor};">
164-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="15" fill="white">
165-
<!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. -->
166-
<path d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"/>
167-
</svg>
154+
<div class="${this.cn([
155+
'w-full flex items-center justify-center',
156+
this.variant === 'arrow'
157+
? this.retroDesign
158+
? 'bg-black px-3'
159+
: 'bg-gray-600 rounded-full p-2'
160+
: this.retroDesign
161+
? 'bg-police-red px-3'
162+
: 'bg-police-red rounded-full p-2',
163+
])}">
164+
<lucide-icon name="ArrowRight"
165+
cls="${this.cn([
166+
'text-white',
167+
this.retroDesign
168+
? 'w-6 h-6'
169+
: 'w-4 h-4',
170+
])}">
171+
</lucide-icon>
168172
</div>`
169173
: ""}
170174
</button>`;

src/components/BlnHeader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {booleanStringFalseConverter} from "../utils/converters";
55

66

77
import './LucideIcon';
8+
import './BlnButton';
9+
import {BlnButton} from "./BlnButton";
810

911
export interface BlnHeaderProps {
1012
class: string;
@@ -62,14 +64,17 @@ export class BlnHeader extends TailwindElement {
6264
</a>
6365
</div>
6466
</section>
65-
<nav class="flex items-center justify-between shadow-md py-4 px-6">
67+
<nav class="flex items-center justify-between shadow-header py-4 px-6">
6668
<div class="min-w-80 max-w-[24vw] overflow-visible">
6769
<a href="${this.titleUrl}">
6870
<small class="block">${this.subTitle}</small>
6971
<span class="block">${this.title}</span>
7072
</a>
7173
</div>
7274
<div class="order-10 grow-0 flex items-end ml-[2vw]">
75+
<bln-button>
76+
test
77+
</bln-button>
7378
<button type="button"
7479
aria-haspopup="true"
7580
aria-expanded="false">

src/components/BlnInput.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import TailwindElement from "../app/TailwindElement";
33
import {html} from "lit";
44
import {booleanStringFalseConverter} from "../utils/converters";
55

6-
76
import './LucideIcon';
87

98
export interface BlnInputProps {

src/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sonarlint.rules": {
3+
"typescript:S3358": {
4+
"level": "off"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)