Skip to content

Commit

Permalink
chore: finish cz-button
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasverleye committed Feb 10, 2025
1 parent 655f931 commit 052ccea
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 39 deletions.
5 changes: 5 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.css?inline' {
import { CSSResultGroup } from 'lit';
const content: CSSResultGroup;
export default content;
}
2 changes: 1 addition & 1 deletion lib/storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { mergeConfig } from 'vite';

const config: StorybookConfig = {
stories: ['../../../packages/**/*.@(mdx|stories.@(js|jsx|ts|tsx))'],
stories: ['../../../packages/**/src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)',],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
framework: {
name: '@storybook/web-components-vite',
Expand Down
2 changes: 1 addition & 1 deletion packages/button/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/button.js';
export * from './lib/button.component.js';
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,37 @@ import { ifDefined } from 'lit/directives/if-defined.js';
import { property } from 'lit/decorators.js';
import { spread } from '@open-wc/lit-helpers';
import classNames from 'classnames';
import { CZButtonProps, CZButtonAppearance, CZButtonSize } from './button.types.js';

import { CraftzingElement, createStyles } from '@design-system/common';

// import { ChLoader } from '../loader/loader.component.ts';
// import { ChIcon } from '../icon/icon.component.ts';
import buttonStyle from './button.css?inline';

import buttonStyle from "./button.css?inline";

/**
* @tag cz-button
* @summary Buttons indicate possible actions or choices to a user.
*
* @csspart base - The component's base wrapper.
* @csspart content - The component's content.
*/
class CZButton extends CraftzingElement {
class CZButton extends CraftzingElement implements CZButtonProps {
static styles:CSSResultGroup = createStyles(buttonStyle);

@property({ type: String, reflect: true })
appearance: 'default' | 'primary' | 'secondary' | 'tertiary' | undefined = 'default';

@property({ type: String, reflect: true })
size: "sm" | "lg" | undefined = "lg";
@property({ reflect: true })
appearance: CZButtonAppearance = "default";

@property({ type: String, reflect: true })
width: "auto" | "full" | undefined = "auto";
size: CZButtonSize = "large";

@property({ type: String, reflect: true })
href: string | undefined;
href = undefined;

// static dependencies = {
// 'ch-loader': ChLoader,
// 'ch-icon': ChIcon,
// };
@property({ type: Boolean, reflect: true })
disabled = false;

render() {
// const iconSize = this.size === 'sm' ? 'sm' : 'md';
const tag = this.href ? literal`a` : literal`button`;
console.log(this.size);

return html`<${tag}
${spread(this.undeclaredAttributes)}
class="${classNames([
'button',
`button--appearance-${this.appearance}`,
`button--size-${this.size}`,
`button--width-${this.width}`,
])}"
href="${ifDefined(this.href && !this.disabled ? this.href : undefined)}"
?disabled="${this.disabled}"
Expand Down
44 changes: 33 additions & 11 deletions packages/button/src/lib/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
align-items: center;
justify-content: center;

font-family: sans-serif;
font-size: 1rem;
line-height: 1.2;
font-weight: 700;

Expand All @@ -16,22 +14,46 @@
--btn-transition: all 0.2s ease-in-out 0s;
transition: var(--btn-transition);

border: var(--px-border-m) solid transparent;

--slotted-icon-size: var(--px-icon-size-xs-mobile);

&:hover:not([disabled], [aria-disabled='true']),
&:focus:not([disabled], [aria-disabled='true']) {
border-color: var(--px-color-border-action-hover-default);
outline: 0;
}
border: 0.125rem solid transparent;

&:active {
transform: scale(0.95);
}

&:hover,
&:focus-visible {
opacity: 0.95;
}

&:where([disabled], [aria-disabled='true']) {
cursor: default;
pointer-events: none;
}
}

.button--appearance-default {
background-color: plum;
color: rgb(29, 29, 29);
}

.button--appearance-primary {
background-color: rebeccapurple;
color: whitesmoke;
}

.button--appearance-secondary {
background-color: whitesmoke;
color: rebeccapurple;
}

.button--size-small {
padding: 0.25rem 0.75rem;
font-family: sans-serif;
font-size: 1rem;
}

.button--size-large {
padding: 0.5rem 1.25rem;
font-family: sans-serif;
font-size: 1.25rem;
}
56 changes: 56 additions & 0 deletions packages/button/src/lib/button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { html } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';

import { CZButton } from './button.component.js';
import { CZButtonProps } from './button.types.js';

CZButton.define('cz-button');

export default {
title: "Components/Button",
component: "cz-button",
tags: ["autodocs"],
render: ({appearance, size, href, disabled}: CZButtonProps) => html`<cz-button
appearance=${ifDefined(appearance)}
size=${ifDefined(size)}
href=${ifDefined(href)}
?disabled=${!!disabled}
>
Craftzing button
</cz-button>`,
argTypes: {
appearance: {
control: { type: 'inline-radio' },
options: ['default', 'primary', 'secondary'],
},
size: {
control: { type: 'inline-radio' },
options: ['small', 'large'],
},
disabled: {
control: { type: 'boolean' },
},
href: {
control: { type: 'text' },
},
},
};

export const Appearance = {
args: {
appearance: 'primary',
size: undefined,
},
};

export const Size = {
args: {
size: 'small',
},
};

export const Link = {
args: {
href: 'https://craftzing.com',
},
};
8 changes: 8 additions & 0 deletions packages/button/src/lib/button.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type CZButtonAppearance = 'default' | 'primary' | 'secondary';
export type CZButtonSize = 'small' | 'large';
export type CZButtonProps = {
appearance?: CZButtonAppearance;
size?: CZButtonSize;
href?: string;
disabled?: boolean;
}
6 changes: 5 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"emitDeclarationOnly": true,
"experimentalDecorators": true,
"importHelpers": true,
"include": [
"./env.d.ts",
],
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "nodenext",
Expand All @@ -22,6 +25,7 @@
],
"skipLibCheck": true,
"strict": true,
"target": "es2022"
"target": "es2022",
"useDefineForClassFields": false,
}
}

0 comments on commit 052ccea

Please sign in to comment.