Skip to content

Commit

Permalink
💄 #24 - style: make the paginator's inputs transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Jan 26, 2024
1 parent 51c89fa commit 44aca1d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/components/form/input/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@
&[type="file"] {
border: none;
}

&--variant-transparent {
background-color: transparent;
}
}
19 changes: 19 additions & 0 deletions src/components/form/input/input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Formik } from "formik";
import React from "react";

import { Button } from "../../button";
import { Page } from "../../page";
import { FORM_TEST_DECORATOR } from "../.storybook/decorators";
import { Input } from "./input";

Expand Down Expand Up @@ -168,6 +169,24 @@ export const InputWithCustomSize: Story = {
decorators: [FORM_TEST_DECORATOR],
};

export const TransparentInput: Story = {
args: {
name: "input",
placeholder: "e.g. John Doe",
type: "text",
variant: "transparent",
},
argTypes: FORM_TEST_ARG_TYPES,
decorators: [
FORM_TEST_DECORATOR,
(Story) => (
<Page>
<Story />
</Page>
),
],
};

export const UsageWithFormik: Story = {
args: {
name: "input",
Expand Down
7 changes: 6 additions & 1 deletion src/components/form/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from "clsx";
import React, { useEffect, useState } from "react";

import { eventFactory } from "../eventFactory";
Expand All @@ -7,6 +8,9 @@ export type InputProps = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
"value"
> & {
/** The variant (style) of the input. */
variant?: "normal" | "transparent";

/** Gets called when the value is changed */
onChange?: React.ChangeEventHandler<HTMLInputElement>;

Expand All @@ -23,6 +27,7 @@ export type InputProps = Omit<
export const Input: React.FC<InputProps> = ({
type = "text",
value,
variant = "normal",
onChange,
...props
}) => {
Expand Down Expand Up @@ -60,7 +65,7 @@ export const Input: React.FC<InputProps> = ({
return (
<input
ref={inputRef}
className="mykn-input"
className={clsx("mykn-input", `mykn-input--variant-${variant}`)}
type={type}
value={valueState}
onChange={_onChange}
Expand Down
4 changes: 4 additions & 0 deletions src/components/form/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
width: fit-content;
}

&--variant-transparent {
background-color: transparent;
}

.mykn-icon {
transition: transform var(--animation-duration-medium)
var(--animation-timing-function);
Expand Down
16 changes: 15 additions & 1 deletion src/components/form/select/select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/react";
import type { Meta, StoryFn, StoryObj } from "@storybook/react";
import { expect, fn, userEvent, waitFor, within } from "@storybook/test";
import { Formik } from "formik";
import React from "react";

import { Button } from "../../button";
import { Page } from "../../page";
import { FORM_TEST_DECORATOR } from "../.storybook/decorators";
import { Select } from "./select";

Expand Down Expand Up @@ -75,6 +76,19 @@ export const SelectComponent: Story = {
},
};

export const TransparentSelect = {
...SelectComponent,
args: { ...SelectComponent.args, variant: "transparent" },
decorators: [
...(SelectComponent.decorators as StoryFn[]),
(Story: StoryFn) => (
<Page>
<Story />
</Page>
),
],
};

export const UsageWithFormik: Story = {
args: {
options: [
Expand Down
6 changes: 5 additions & 1 deletion src/components/form/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export type SelectProps = React.HTMLAttributes<HTMLDivElement> & {
size?: "fit-content";

value?: Option["value"] | null;

/** The variant (style) of the input. */
variant?: "normal" | "transparent";
} & SelectRequiredConditional;

type SelectRequiredConditional =
Expand Down Expand Up @@ -92,6 +95,7 @@ export const Select: React.FC<SelectProps> = ({
required = false,
size,
value = null,
variant = "normal",
...props
}) => {
const fakeInputRef = React.useRef<HTMLSelectElement>(null);
Expand Down Expand Up @@ -179,7 +183,7 @@ export const Select: React.FC<SelectProps> = ({
return (
<>
<div
className={clsx("mykn-select", {
className={clsx("mykn-select", `mykn-select--variant-${variant}`, {
"mykn-select--selected": selectedIndex,
[`mykn-select--size-${size}`]: size,
})}
Expand Down
2 changes: 2 additions & 0 deletions src/components/paginator/paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const Paginator: React.FC<PaginatorProps> = ({
required={true}
size="fit-content"
value={pageSizeState}
variant="transparent"
onChange={handlePageSizeChange}
/>
</>
Expand All @@ -201,6 +202,7 @@ export const Paginator: React.FC<PaginatorProps> = ({
size={String(pageCount).length}
type="number"
value={pageState}
variant="transparent"
onChange={handlePageChange}
></Input>
</div>
Expand Down

0 comments on commit 44aca1d

Please sign in to comment.