From 52ba835f049b24409e814edcc5b0516d6ed6e9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melihcan=20=C3=87ilek?= Date: Fri, 1 Sep 2023 12:04:19 +0300 Subject: [PATCH] feat(apps/studio): Checkbox implementation for Storybook (#688) # Description - Added Default, With Text, Inside Form, OnFocus and Default Check parts done for checkbox Storybook. - checked, disable, asChild and children props can be changed from the table. ### Checklist - [x] discord username: `cilek` - [x] Closes #669 - [x] PR must be created for an issue from issues under "In progress" column from [our project board](https://github.com/orgs/kamp-us/projects/2/views/1). - [ ] A descriptive and understandable title: The PR title should clearly describe the nature and purpose of the changes. The PR title should be the first thing displayed when the PR is opened. And it should follow the semantic commit rules, and should include the app/package/service name in the title. For example, a title like "docs(@kampus-apps/pano): Add README.md" can be used. - [ ] Related file selection: Only relevant files should be touched and no other files should be affected. - [ ] I ran `npx turbo run` at the root of the repository, and build was successful. - [ ] I installed the npm packages using `npm install --save-exact ` so my package is pinned to a specific npm version. Leave empty if no package was installed. Leave empty if no package was installed with this PR. ### How were these changes tested? Please describe the tests you did to test the changes you made. Please also specify your test configuration. --------- Co-authored-by: Can Sirin --- apps/studio/stories/Checkbox.stories.tsx | 199 ++++++++++++++++++++--- 1 file changed, 178 insertions(+), 21 deletions(-) diff --git a/apps/studio/stories/Checkbox.stories.tsx b/apps/studio/stories/Checkbox.stories.tsx index cf2a5532..dde103d1 100644 --- a/apps/studio/stories/Checkbox.stories.tsx +++ b/apps/studio/stories/Checkbox.stories.tsx @@ -1,34 +1,191 @@ import { Meta, StoryObj } from "@storybook/react"; -import { Checkbox, Label } from "@kampus/ui"; - -const labels = ["köpekleri çıkarmak", "alışverişe gitmek", "kitap okumak"]; +import { Button, Checkbox, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, Label, toast, useForm, z } from "@kampus/ui"; +import { zodResolver } from "@hookform/resolvers/zod" +import { useState } from "react"; const meta = { title: "Checkbox", + tags: ["autodocs"], component: Checkbox, + argTypes: { + disabled: { + control: "boolean", + }, + checked: { + control: "boolean", + }, + } } satisfies Meta; export default meta; -type NewType = StoryObj; -export const Default = { - render: () => ( +type Story = StoryObj; + +export const DefaultChecked = { + args: { + defaultChecked: true, + }, +} satisfies Story; + +const OnFocusTemplate = ({ ...props }) => { + const [isFocused, setIsFocused] = useState(false) + return (
-

Günlük Yapmam Gerekenler

- {labels.map((label) => { - return ( -
- - -
- ); - })} +
+ { + setIsFocused(true) + }} + onBlur={() => { + setIsFocused(false) + }} + {...props} /> + +
+ ) +} + +export const OnFocus = { + render: ({ ...props }) => , +} satisfies Story; + +const DefaultTemplate = ({ ...props }) => { + return ( + +
+ +
+ + {props?.description && ( +

+ {props?.description} +

+ )} + {props?.error && ( +

+ {props?.error} +

+ )} +
+
+ ) +} + +export const WithError = { + argTypes: { + disabled: { + control: "boolean", + }, + checked: { + control: "boolean", + } + }, + render: ({ ...props }) => ( + + ), +} satisfies Story; + +export const WithText = { + argTypes: { + disabled: { + control: "boolean", + }, + checked: { + control: "boolean", + } + }, + render: ({ ...props }) => ( + ), -}; +} satisfies Story; + +const FormComponent = ({ ...props }) => { + const FormSchema = z.object({ + mobile: z.boolean().default(false).optional(), + }) + + function onSubmit(data: z.infer) { + toast({ + title: "You submitted the following values:", + description: ( +
+          {JSON.stringify(data, null, 2)}
+        
+ ), + }) + } + + const form = useForm>( + FormSchema, + { + resolver: zodResolver(FormSchema), + values: { + mobile: props?.checked, + } + }, + ) + + return ( +
+ + ( + + + + +
+ + Use different settings for my mobile devices + + + You can manage your mobile notifications in the mobile settings page. + +
+
+ )} + /> + + + + ) +} + +export const InsideForm = { + render: ({ ...props }) => +} satisfies Story; + + +export const Default = { + args: { + children: "Default" + }, + render: ( + { ...props } + ) => ( + + ) +} satisfies Story;