Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ export const _SidebarProvider = (
(value: SidebarState | ((value: SidebarState) => SidebarState)) => {
const computedState = typeof value === "function" ? value(state) : value;

if (setStateProp) {
setStateProp(computedState);
} else {
_setState(computedState);
}
_setState(computedState);
setStateProp?.(computedState);
},
[setStateProp, state],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useState } from "react";
import {
Sidebar,
SidebarTrigger,
SidebarProvider,
type SidebarState,
type SidebarProps,
} from "../src/index";
import { Flex } from "../../Flex";

type ControlledStateSidebarProps = SidebarProps & {
children: React.ReactNode;
};
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing SidebarProps type import

The type SidebarProps is used but not explicitly imported. Consider adding it to the named imports.

 import {
   Sidebar,
   SidebarTrigger,
   SidebarProvider,
   type SidebarState,
+  type SidebarProps,
 } from "../src/index";

Committable suggestion skipped: line range outside the PR's diff.


export const ControlledStateSidebar = (props: ControlledStateSidebarProps) => {
const { children, ...sidebarProps } = props;
const [state, setState] = useState<SidebarState>("collapsed");

return (
<SidebarProvider
onStateChange={setState}
side="start"
state={state}
style={{
height: "50vh",
border: "1px solid var(--color-bd-elevation-1)",
}}
>
<Sidebar {...sidebarProps}>{children}</Sidebar>
<Flex alignItems="start" margin="spacing-4" width="100%">
<SidebarTrigger />
</Flex>
</SidebarProvider>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { Sidebar, SidebarTrigger, SidebarProvider } from "../src/index";
import { Flex } from "../../Flex";
import { Text, Icon } from "@appsmith/wds";
import { Text, Icon, Flex } from "@appsmith/wds";

import { ControlledStateSidebar } from "./ControlledStateSidebar";

const meta: Meta<typeof Sidebar> = {
component: Sidebar,
Expand Down Expand Up @@ -126,3 +127,13 @@ export const WithRenderProps: Story = {
</SidebarProvider>
),
};

export const WithControlledState: Story = {
render: (args) => {
return (
<ControlledStateSidebar {...args}>
<DemoContent />
</ControlledStateSidebar>
);
},
};