Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk committed Feb 24, 2025
1 parent 24a08a4 commit 1946527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .changeset/tall-boxes-matter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
'@toptal/picasso-section': minor
---

- make Section component controlled
### Section

- add controlled component behavior support
21 changes: 14 additions & 7 deletions packages/base/Section/src/Section/story/Controlled.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@ import React, { useState } from 'react'
import { Button, Container, Section } from '@toptal/picasso'
import { SPACING_4 } from '@toptal/picasso-utils'

const FIRST_SECTION_ID = 0
const SECOND_SECTION_ID = 1

const Example = () => {
const [expandedSection, setExpandedSection] = useState(0)
const [expandedSection, setExpandedSection] = useState(FIRST_SECTION_ID)

return (
<>
<Section
collapsible
onToggle={collapsed => setExpandedSection(collapsed ? 1 : 0)}
onToggle={collapsed =>
setExpandedSection(collapsed ? SECOND_SECTION_ID : FIRST_SECTION_ID)
}
variant='bordered'
title='First section'
collapsed={expandedSection !== 0}
collapsed={expandedSection !== FIRST_SECTION_ID}
>
<p>First section content</p>
<Button onClick={() => setExpandedSection(1)}>
<Button onClick={() => setExpandedSection(SECOND_SECTION_ID)}>
Go to second section
</Button>
</Section>
<Container top={SPACING_4}>
<Section
collapsible
onToggle={collapsed => setExpandedSection(collapsed ? 0 : 1)}
onToggle={collapsed =>
setExpandedSection(collapsed ? FIRST_SECTION_ID : SECOND_SECTION_ID)
}
variant='bordered'
title='Second section'
collapsed={expandedSection !== 1}
collapsed={expandedSection !== SECOND_SECTION_ID}
>
<p>Second section content</p>
<Button onClick={() => setExpandedSection(0)}>
<Button onClick={() => setExpandedSection(FIRST_SECTION_ID)}>
Go to first section
</Button>
</Section>
Expand Down

0 comments on commit 1946527

Please sign in to comment.