Skip to content

Commit 0f0cda0

Browse files
siddharthkpSaraVieira
authored andcommitted
components: use Text in Collapsible (codesandbox#3291)
* use text inside collapsible * use size instead of absolute ✨ * prefer element method
1 parent df97023 commit 0f0cda0

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import React from 'react';
22
import { Collapsible } from '.';
3+
import { Text } from '../Text';
4+
import { Element } from '../Element';
35

46
export default {
57
title: 'components/Collapsible',
68
component: Collapsible,
79
};
810

9-
// replace the text inside with Text variants when available
1011
export const Basic = () => (
11-
<Collapsible title="Files">
12-
The move from Cerebral
13-
<br />
14-
This is a static template with no bundling
12+
<Collapsible title="Sandbox Info">
13+
<Element marginX={2}>
14+
<Text weight="medium" marginBottom={2}>
15+
The move from Cerebral
16+
</Text>
17+
<Text variant="muted">This is a static template with no bundling</Text>
18+
</Element>
1519
</Collapsible>
1620
);
1721

1822
export const DefaultOpen = () => (
19-
<Collapsible title="Files" defaultOpen>
20-
The move from Cerebral
21-
<br />
22-
This is a static template with no bundling
23+
<Collapsible title="Sandbox Info" defaultOpen>
24+
<Element marginX={2}>
25+
<Text as="div" weight="medium" marginBottom={2}>
26+
The move from Cerebral
27+
</Text>
28+
<Text variant="muted">This is a static template with no bundling</Text>
29+
</Element>
2330
</Collapsible>
2431
);

packages/components/src/components/Collapsible/index.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import React from 'react';
22
import styled from 'styled-components';
33
import css from '@styled-system/css';
44
import { Element } from '../Element';
5+
import { Text } from '../Text';
6+
7+
export const Section = styled(Element).attrs({ as: 'section' })(
8+
css({
9+
fontSize: 3,
10+
})
11+
);
512

613
export const Header = styled.div(
714
css({
815
display: 'flex',
916
alignItems: 'center',
10-
height: '32px',
17+
height: 6,
1118
paddingX: 3,
1219
borderBottom: '1px solid',
1320
// Note: sideBarSectionHeader exists but we dont use it because it is rarely implemented
@@ -24,14 +31,6 @@ export const Header = styled.div(
2431
})
2532
);
2633

27-
// temporary: replace with <Text variant="strong">
28-
export const Title = styled.div(
29-
css({
30-
fontSize: 3,
31-
fontWeight: 'semibold',
32-
})
33-
);
34-
3534
// temporary: replace with <Icon name="triangle/toggle">
3635
export const Icon = styled.svg<{
3736
open?: boolean;
@@ -82,12 +81,12 @@ export const Collapsible: React.FC<ICollapsibleProps> = ({
8281
const toggle = () => setOpen(!open);
8382

8483
return (
85-
<Element as="section" {...props}>
84+
<Section {...props}>
8685
<Header onClick={toggle}>
8786
<ToggleIcon open={open} />
88-
<Title>{title}</Title>
87+
<Text weight="medium">{title}</Text>
8988
</Header>
9089
{open ? <Body>{children}</Body> : null}
91-
</Element>
90+
</Section>
9291
);
9392
};

0 commit comments

Comments
 (0)