Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping size array prop with components sizes + added example for avatar responsive size #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions packages/docs/src/pages/components/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ const Documentation = () => {
<Avatar size="large" src="https://github.com/sameen-shi.png" />
`}</Example.Code>
</Example>

<Example title="Responsive Size">
<Para>
<Text variant="subtle" size={3}>
(Try resizing the browser window to see this in effect. If you're
on mobile, try switching to landscape mode)
</Text>
</Para>
<Example.Preview>
<Avatar
size={['small', 'medium', 'large']}
src="https://github.com/sameen-shi.png"
/>
</Example.Preview>
<Example.Code>{`
<Avatar size={["small", "medium", "large"]} src="https://github.com/sameen-shi.png" />
`}</Example.Code>
</Example>
</Section>

<Section title="Customisation">
Expand Down
5 changes: 4 additions & 1 deletion packages/react-ui/src/components/avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Avatar.propTypes = {
/** Image url for avatar */
src: PropTypes.string.isRequired,
/** size of avatar */
size: PropTypes.string
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string)
])
}

Avatar.defaultProps = {}
5 changes: 4 additions & 1 deletion packages/react-ui/src/primitives/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ function Element(
if (typeof theme.sizes[component] !== 'object') {
// single value, attach to component
value = theme.sizes[component]
} else if (Array.isArray(size)) {
// if its multiple values and size is array (responsive), attach the corresponding key
value = size.map(s => theme.sizes[component][s]);
} else {
// if its multiple values, attach the corresponding key
// if its multiple values and size is single value (non reponsive), attach the corresponding key
value = theme.sizes[component][size]
}

Expand Down