Skip to content

Commit

Permalink
Merge pull request #14 from maykinmedia/feature/#12-boolean
Browse files Browse the repository at this point in the history
#12 - feat: add boolean component
  • Loading branch information
svenvandescheur authored Jan 26, 2024
2 parents 464af4e + 8266cfc commit 2a82cea
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/components/boolean/boolean.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@import "../../settings/style";

.mykn-boolean {
align-items: center;
border-radius: var(--border-radus-m);
display: inline-flex;
font-size: var(--typography-font-size-body-s);
justify-content: center;
height: var(--typography-line-height-body-s);
width: var(--typography-line-height-body-s);

&--value-true {
background-color: var(--theme-color-success-background);
color: var(--theme-color-success-body);
}

&--explicit#{&}--value-false {
background-color: var(--theme-color-danger-background);
color: var(--theme-color-danger-body);
}
}
84 changes: 84 additions & 0 deletions src/components/boolean/boolean.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type { Meta, StoryObj } from "@storybook/react";
import { expect, within } from "@storybook/test";
import React from "react";

import { Body, H1, H2, H3, P } from "../typography";
import { Boolean } from "./boolean";

const meta = {
title: "Icon/Boolean",
component: Boolean,
} satisfies Meta<typeof Boolean>;

export default meta;
type Story = StoryObj<typeof meta>;

export const True: Story = {
args: {
value: true,
labelTrue: "This value is true",
labelFalse: "This value is false",
},
play: ({ canvasElement }) => {
const canvas = within(canvasElement);
const boolean = canvas.getByLabelText("This value is true");
expect(boolean).toBeVisible();
expect(boolean.children).toHaveLength(1);
},
};

export const False: Story = {
args: {
value: false,
labelTrue: "This value is true",
labelFalse: "This value is false",
},
play: ({ canvasElement }) => {
const canvas = within(canvasElement);
const boolean = canvas.getByLabelText("This value is false");
expect(boolean).toBeVisible();
expect(boolean.children).toHaveLength(0);
},
};

export const ExplicitFalse: Story = {
args: {
explicit: true,
value: false,
labelTrue: "This value is true",
labelFalse: "This value is false",
},
play: ({ canvasElement }) => {
const canvas = within(canvasElement);
const boolean = canvas.getByLabelText("This value is false");
expect(boolean.children).toHaveLength(1);
},
};

export const BooleanInText: Story = {
args: {
value: true,
labelTrue: "This value is true",
labelFalse: "This value is false",
},
render: (args) => (
<Body>
<H1>
The quick brown fox jumps over the lazy dog <Boolean {...args} />
</H1>
<H2>
The quick brown fox jumps over the lazy dog <Boolean {...args} />
</H2>
<H3>
The quick brown fox jumps over the lazy dog <Boolean {...args} />
</H3>
<P size="s">
The quick brown fox jumps over the lazy dog{" "}
<Boolean {...args} value={false} explicit />
</P>
<P size="xs">
The quick brown fox jumps over the lazy dog <Boolean {...args} />
</P>
</Body>
),
};
46 changes: 46 additions & 0 deletions src/components/boolean/boolean.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import clsx from "clsx";
import React from "react";

import { Outline } from "../../components/icon";
import "./boolean.scss";

export type BooleanProps = {
/** The accessible label when value is true. */
labelTrue: string;

/** The accessible label when value is false. */
labelFalse: string;

/** The value. */
value: boolean;

/** Show an icon, even if value is false. */
explicit?: boolean;
};

/**
* Boolean component, shows a checkmark if `value` is `true`. If `value` is
* `false` the icon is hidden, unless `explicit` is `true`.
* @param children
* @param props
* @constructor
*/
export const Boolean: React.FC<BooleanProps> = ({
explicit = false,
value,
labelTrue,
labelFalse,
...props
}) => (
<div
className={clsx("mykn-boolean", `mykn-boolean--value-${value}`, {
"mykn-boolean--explicit": explicit,
})}
{...props}
title={value ? labelTrue : labelFalse}
aria-label={value ? labelTrue : labelFalse}
>
{value && <Outline.CheckIcon />}
{!value && explicit && <Outline.XMarkIcon />}
</div>
);
1 change: 1 addition & 0 deletions src/components/boolean/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./boolean";
15 changes: 8 additions & 7 deletions src/components/button/button.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use '../../settings/style';
@use "../../settings/style";

.mykn-button {
--mykn-button-color-background: var(--theme-color-primary-800);
Expand All @@ -12,8 +12,9 @@
padding: var(--spacing-v-s) var(--spacing-h-s);
background-color: var(--mykn-button-color-background);
border: 1px solid var(--mykn-button-color-border);
border-radius: 4px;
box-shadow: 0 calc(var(--mykn-button-offset) * -1) var(--mykn-button-color-shadow);
border-radius: var(--border-radus-m);
box-shadow: 0 calc(var(--mykn-button-offset) * -1)
var(--mykn-button-color-shadow);
box-sizing: border-box;
color: var(--mykn-button-color-text);
cursor: pointer;
Expand All @@ -26,18 +27,18 @@
line-height: var(--typography-line-height-body-s);
text-align: center;
text-decoration: none;
transition: all var(--animation-duration-fast) var(--animation-timing-function);
transition: all var(--animation-duration-fast)
var(--animation-timing-function);
transform: translateY(var(--mykn-button-offset));


&--variant-primary {
&:focus,
&:hover {
--mykn-button-color-background: var(--theme-color-primary-700);
--mykn-button-offset: -2px;
}

&[aria-expanded=true],
&[aria-expanded="true"],
&:active {
--mykn-button-color-background: var(--theme-color-primary-800);
--mykn-button-offset: 0px;
Expand All @@ -55,7 +56,7 @@
--mykn-button-offset: -2px;
}

&[aria-expanded=true],
&[aria-expanded="true"],
&:active {
--mykn-button-color-background: var(--typography-color-background);
--mykn-button-offset: 0px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/card/card.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.mykn-card {
background-color: var(--typography-color-background);
border-radius: 12px;
border-radius: var(--border-radus-l);
box-sizing: border-box;
padding: var(--spacing-v-xxl) var(--spacing-h-xxl);

Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
&__dropdown {
width: fit-content;
border: 1px solid var(--theme-color-primary-800);
border-radius: 4px;
border-radius: var(--border-radus-m);
box-sizing: border-box;
padding: 2px;
z-index: 1000;
Expand Down
4 changes: 2 additions & 2 deletions src/components/form/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
align-items: center;
background: var(--typography-color-background);
border: 1px solid var(--theme-color-primary-800);
border-radius: 6px;
border-radius: var(--border-radus-m);
box-sizing: border-box;
color: var(--typography-color-body);
cursor: pointer;
Expand Down Expand Up @@ -51,7 +51,7 @@
&__dropdown {
background: var(--typography-color-background);
border: 1px solid var(--theme-color-primary-800);
border-radius: 4px;
border-radius: var(--border-radus-m);
box-sizing: border-box;
min-width: 100%;
padding: var(--spacing-v-s) 0;
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Auto-generated file. Do not modify manually.
export * from "./boolean";
export * from "./button";
export * from "./card";
export * from "./dropdown";
Expand Down
9 changes: 9 additions & 0 deletions src/settings/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
--theme-shade-300: #eaeaea;
--theme-shade-0: #fff;

--theme-color-success-body: #0b4f00;
--theme-color-success-background: #e9ffe9;

--theme-color-danger-body: #ff4545;
--theme-color-danger-background: #{rgba(#ff4545, 0.1)};

/// SPACING
--border-radus-l: 12px;
--border-radus-m: 6px;

--gutter-h-desktop: 12px;
--gutter-v-desktop: 24px;

Expand Down

0 comments on commit 2a82cea

Please sign in to comment.