Skip to content

Commit

Permalink
Merge pull request #50 from auung/feature/component-stories-4
Browse files Browse the repository at this point in the history
feat(packages|components): add stories for input, label, pagination, and popover components
  • Loading branch information
HTLA380 authored Dec 29, 2024
2 parents 2a6d044 + 782c531 commit 3a0f64d
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/components/input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@mijn-ui/react-theme": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-icons": "^5.3.0",
"@next/eslint-plugin-next": "^15.0.3",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
94 changes: 94 additions & 0 deletions packages/components/input/src/input.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { Meta, StoryObj } from "@storybook/react"
import { Input, InputProps } from "./input"
import { LuPlus } from "react-icons/lu"

const meta: Meta<typeof Input> = {
title: "Components/Input",
component: Input,
parameters: {
layout: "centered",
},
args: {
placeholder: "Username...",
disabled: false,
unstyled: false,
},
argTypes: {
label: {
type: "string",
},
placeholder: {
type: "string",
},
startIcon: {
table: {
disable: true,
},
},
endIcon: {
table: {
disable: true,
},
},
classNames: {
table: {
disable: true,
},
},
},
}

export default meta
type Story = StoryObj<typeof Input>

const InputTemplate = (args: InputProps) => {
return <Input className="w-80" {...args} />
}

const InputWithIcons = (args: InputProps) => {
return (
<div className="flex flex-col gap-2">
<Input className="w-80" {...args} endIcon={undefined} />
<Input className="w-80" {...args} startIcon={undefined} />
<Input className="w-80" {...args} />
</div>
)
}

export const Default: Story = {
render: InputTemplate,
}

export const WithIcon: Story = {
render: InputWithIcons,
args: {
startIcon: <LuPlus />,
endIcon: <LuPlus />,
},
}

export const WithFloatingLabel: Story = {
render: InputTemplate,
args: {
placeholder: "",
label: "Username",
},
}

export const WithFloatingLabelAndIcon: Story = {
render: InputWithIcons,
args: {
placeholder: "",
label: "Username",
startIcon: <LuPlus />,
endIcon: <LuPlus />,
},
}

export const Unstyled: Story = {
render: InputTemplate,
args: {
unstyled: true,
classNames: { input: "indent-2 py-1" },
},
}
2 changes: 1 addition & 1 deletion packages/components/input/src/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { InputSlots, inputStyles } from "@mijn-ui/react-theme"
import { cn } from "@mijn-ui/react-utilities"

type InputProps = UnstyledComponentWithSlots<InputSlots> &
export type InputProps = UnstyledComponentWithSlots<InputSlots> &
React.ComponentPropsWithRef<"input"> & {
startIcon?: React.ReactNode
endIcon?: React.ReactNode
Expand Down
1 change: 1 addition & 0 deletions packages/components/label/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"types:check": "tsc --noEmit"
},
"devDependencies": {
"@mijn-ui/react-button": "workspace:*",
"@mijn-ui/react-core": "workspace:*",
"@mijn-ui/react-theme": "workspace:*",
"react": "19.0.0",
Expand Down
54 changes: 54 additions & 0 deletions packages/components/label/src/label.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { Meta, StoryObj } from "@storybook/react"
import { Label, LabelProps } from "./label"
import { Button } from "@mijn-ui/react-button"

const meta: Meta<typeof Label> = {
title: "Components/Label",
component: Label,
parameters: {
layout: "centered",
},
args: {
unstyled: false,
},
}

export default meta
type Story = StoryObj<typeof Label>

const LabelTemplate = (args: LabelProps) => {
return (
<div className="flex flex-col gap-2">
<Label htmlFor="comment" {...args}>
Feedback
</Label>
<textarea
id="comment"
name="comment"
className={
args.unstyled
? "indent-2"
: "border-input placeholder:text-muted-text focus-visible:ring-ring flex min-h-[80px] w-full rounded-md border bg-transparent px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-50"
}
placeholder="Enter your feedback ..."
></textarea>
<Button
unstyled={args.unstyled}
className={args.unstyled ? "bg-accent w-full py-2" : ""}
>
Submit
</Button>
</div>
)
}

export const Default: Story = {
render: LabelTemplate,
}

export const Unstyled: Story = {
render: LabelTemplate,
args: {
unstyled: true,
},
}
1 change: 1 addition & 0 deletions packages/components/pagination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@mijn-ui/react-theme": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-icons": "^5.3.0",
"@next/eslint-plugin-next": "^15.0.3",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
104 changes: 104 additions & 0 deletions packages/components/pagination/src/pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { Meta, StoryObj } from "@storybook/react"
import {
Pagination,
PaginationProps,
PaginationContent,
PaginationList,
PaginationNextButton,
PaginationNextEllipsis,
PaginationPreviousButton,
PaginationPreviousEllipsis,
} from "./pagination"
import { LuChevronLeft, LuChevronRight } from "react-icons/lu"
import React from "react"

const meta: Meta<typeof Pagination> = {
title: "Components/Pagination",
component: Pagination,
parameters: {
layout: "centered",
},
args: {
currentPage: 7,
itemsPerPage: 10,
totalPages: 160,
unstyled: false,
},
argTypes: {
children: {
table: {
disable: true,
},
},
},
}

export default meta
type Story = StoryObj<typeof Pagination>

const PaginationTemplate = (args: PaginationProps) => {
const [currentPage, setCurrentPage] = React.useState(args.currentPage)

return (
<Pagination
totalPages={args.totalPages}
currentPage={currentPage}
itemsPerPage={args.itemsPerPage}
onChangePage={setCurrentPage}
unstyled={args.unstyled}
>
<PaginationContent>
<PaginationPreviousButton className="h-9 sm:h-10">
<LuChevronLeft className="size-4" />
<span className="hidden sm:inline">Previous</span>
</PaginationPreviousButton>
<PaginationPreviousEllipsis />
<PaginationList className="[&>li>button]:size-9 sm:[&>li>button]:size-10" />
<PaginationNextEllipsis className="[&>svg]:size-3.5 sm:[&>svg]:size-4" />
<PaginationNextButton className="h-9 sm:h-10">
<span className="hidden sm:inline">Next</span>
<LuChevronRight className="size-4" />
</PaginationNextButton>
</PaginationContent>
</Pagination>
)
}

const PaginationUnstyled = (args: PaginationProps) => {
const [currentPage, setCurrentPage] = React.useState(args.currentPage)

return (
<Pagination
totalPages={args.totalPages}
currentPage={currentPage}
itemsPerPage={args.itemsPerPage}
onChangePage={setCurrentPage}
unstyled={args.unstyled}
>
<PaginationContent className="flex items-center gap-2">
<PaginationPreviousButton className="flex h-9 items-center gap-2 sm:h-10">
<LuChevronLeft className="size-4" />
<span className="hidden sm:inline">Previous</span>
</PaginationPreviousButton>
<PaginationPreviousEllipsis />
<PaginationList className="flex items-center gap-2 [&>li>button]:size-9 sm:[&>li>button]:size-10" />
<PaginationNextEllipsis className="[&>svg]:size-3.5 sm:[&>svg]:size-4" />
<PaginationNextButton className="flex h-9 items-center gap-2 sm:h-10">
<span className="hidden sm:inline">Next</span>
<LuChevronRight className="size-4" />
</PaginationNextButton>
</PaginationContent>
</Pagination>
)
}

export const Default: Story = {
render: (args: PaginationProps) => <PaginationTemplate {...args} />,
}

export const Unstyled: Story = {
render: (args: PaginationProps) => <PaginationUnstyled {...args} />,
args: {
unstyled: true,
},
}
4 changes: 4 additions & 0 deletions packages/components/popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
"types:check": "tsc --noEmit"
},
"devDependencies": {
"@mijn-ui/react-button": "workspace:*",
"@mijn-ui/react-label": "workspace:*",
"@mijn-ui/react-input": "workspace:*",
"@mijn-ui/react-core": "workspace:*",
"@mijn-ui/react-theme": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-icons": "^5.3.0",
"@next/eslint-plugin-next": "^15.0.3",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
Loading

1 comment on commit 3a0f64d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for mijn-ui-react ready!

✅ Preview
https://mijn-ui-react-btprnsw0c-htla380s-projects.vercel.app

Built with commit 3a0f64d.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.