Skip to content

Commit b4decb1

Browse files
committed
feat: add default closed groups prop
1 parent 3a59f47 commit b4decb1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/Controls.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ const groupByGroup = (items: any): any => {
5353
}, {} as { [key: string]: any });
5454
}
5555

56-
export const Controls = React.memo(() => {
56+
interface ControlsProps {
57+
defaultClosedGroups?: string[]
58+
}
59+
60+
export const Controls = React.memo((props?: ControlsProps) => {
5761
const [{ pos }, setPos] = useSpring(() => ({ pos: [0, 0] }));
5862
const bind = useDrag(({ movement, memo = ((pos as any).getValue ? (pos as any).getValue() : (pos as any).get()) }) => {
5963
setPos({
@@ -73,6 +77,12 @@ export const Controls = React.memo(() => {
7377
};
7478
}, []);
7579

80+
const getGroupConfig = (groupName: string): any => {
81+
return {
82+
defaultClosed: props?.defaultClosedGroups?.includes(groupName) ?? false
83+
}
84+
}
85+
7686
return (
7787
<Float
7888
style={{
@@ -85,7 +95,7 @@ export const Controls = React.memo(() => {
8595
<Header {...bind()} />
8696
<Items>
8797
{Object.entries(groupByGroup(controls)).map(([groupName, items]: any) => (
88-
<ControlGroup key={groupName} title={groupName} controls={items} />
98+
<ControlGroup key={groupName} title={groupName} controls={items} config={getGroupConfig(groupName)} />
8999
))}
90100
</Items>
91101
</Float>

src/components/ControlGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const Container = styled.div<{ open: boolean, bg: boolean }>`
3939
margin-bottom: 8px;
4040
`;
4141

42-
export const ControlGroup = ({ title, controls }: any) => {
43-
const [open, setOpen] = useState(true);
42+
export const ControlGroup = ({ title, controls, config }: any) => {
43+
const [open, setOpen] = useState(!config.defaultClosed ?? true);
4444
const isDefault = title !== 'DEFAULT_GROUP';
4545
return (
4646
<div>

0 commit comments

Comments
 (0)