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

Added fullWidth prop to multiple components #50

Open
wants to merge 2 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
70 changes: 69 additions & 1 deletion packages/docs/src/pages/components/card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { ThemeProvider, Card, Stack, Link, Text } from 'react-ui'
import { Page, Example, Section, Table, Para } from '../../components'
import { Page, Props, Example, Section, Table, Para } from '../../components'

const Documentation = () => {
return (
Expand All @@ -16,6 +16,19 @@ const Documentation = () => {
</Example.Code>
</Example>

<Section title="Props">
<Props
props={[
{
name: 'fullWidth',
type: 'boolean',
description: 'Make card take 100% width of the container',
default: 'false'
}
]}
/>
</Section>

<Section title="Examples">
<Example>
<Example.Preview>
Expand Down Expand Up @@ -71,6 +84,61 @@ const Documentation = () => {
</Card>
`}</Example.Code>
</Example>

<Example title="Full width">
<Example.Preview>
<Card fullWidth>
<Stack justify="center">
<Stack justify="space-between" align="center">
<Stack direction="vertical" align="flex-end">
<Text size={6}>09:15</Text>
<Text size={4} variant="subtle">
AMS
</Text>
</Stack>
<Stack
direction="vertical"
align="center"
css={{ paddingX: 8 }}
>
<Text size={2}>8h 35</Text>
<Text size={1}>Direct</Text>
</Stack>
<Stack direction="vertical" align="flex-start">
<Text size={6}>11:50</Text>
<Text size={4} variant="subtle">
JFK
</Text>
</Stack>
</Stack>
</Stack>
</Card>
</Example.Preview>
<Example.Code>{`
<Card fullWidth>
<Stack justify="center">
<Stack justify="space-between" align="center">

<Stack direction="vertical" align="flex-end">
<Text size={6}>09:15</Text>
<Text size={4} variant="subtle">AMS</Text>
</Stack>

<Stack direction="vertical" align="center" css={{ paddingX: 8 }}>
<Text size={2}>8h 35</Text>
<Text size={1}>Direct</Text>
</Stack>

<Stack direction="vertical" align="flex-start">
<Text size={6}>11:50</Text>
<Text size={4} variant="subtle">JFK</Text>
</Stack>

</Stack>
</Stack>
</Card>
`}</Example.Code>
</Example>
</Section>

<Section title="Customisation">
Expand Down
17 changes: 17 additions & 0 deletions packages/docs/src/pages/components/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const Documentation = () => {
description:
'type of avatar, example: text, password, number, etc.',
default: 'text'
},
{
name: 'fullWidth',
type: 'boolean',
description: 'Make input take 100% width of the container',
default: 'false'
}
]}
/>
Expand All @@ -54,6 +60,17 @@ const Documentation = () => {
<Input type="text" invalid placeholder="Please enter your name" />
`}</Example.Code>
</Example>

<Example title="Full width">
<Example.Preview>
<Input type="text" placeholder="Please enter your name" fullWidth />
</Example.Preview>
<Example.Code>
{`
<Input type="text" placeholder="Please enter your name" fullWidth />
`}
</Example.Code>
</Example>
</Section>

<Section title="Customisation">
Expand Down
27 changes: 27 additions & 0 deletions packages/docs/src/pages/components/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const Documentation = () => {
name: '+',
type: 'props of Input',
description: ''
},
{
name: 'fullWidth',
type: 'boolean',
description: 'Make select take 100% width of the container',
default: 'false'
}
]}
/>
Expand Down Expand Up @@ -88,6 +94,27 @@ const Documentation = () => {
</Select>
`}</Example.Code>
</Example>

<Example title="Full width">
<Example.Preview>
<Select fullWidth>
<option>Please select an option</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</Select>
</Example.Preview>
<Example.Code>
{`
<Select fullWidth>
<option>Please select an option</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</Select>
`}
</Example.Code>
</Example>
</Section>

<Section title="Customisation">
Expand Down
17 changes: 17 additions & 0 deletions packages/docs/src/pages/components/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const Documentation = () => {
name: '+',
type: 'props of Input',
description: ''
},
{
name: 'fullWidth',
type: 'boolean',
description: 'Make textarea take 100% width of the container',
default: 'false'
}
]}
/>
Expand All @@ -58,6 +64,17 @@ const Documentation = () => {
<Textarea invalid placeholder="Please enter your address" />
`}</Example.Code>
</Example>

<Example title="Full width">
<Example.Preview>
<Textarea placeholder="Please enter your address" fullWidth />
</Example.Preview>
<Example.Code>
{`
<Textarea placeholder="Please enter your address" fullWidth />
`}
</Example.Code>
</Example>
</Section>

<Section title="Customisation">
Expand Down
12 changes: 10 additions & 2 deletions packages/react-ui/src/components/card/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Element } from '../../primitives'
import { styles } from './card.styles'
import { merge } from '../../utils'

const Card = React.forwardRef(function Card({ css, ...props }, ref) {
const Card = React.forwardRef(function Card({ fullWidth, css, ...props }, ref) {
let width = fullWidth ? '100%' : 'auto'

return (
<Element
ref={ref}
as="div"
component="Card"
css={merge(styles.Card, css)}
css={merge(styles.Card, { width }, css)}
{...props}
/>
)
})

Card.propTypes = {
/** Description of an card prop */
fullWidth: PropTypes.bool
}

export { Card }
7 changes: 5 additions & 2 deletions packages/react-ui/src/components/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import { styles } from './input.styles'
import { merge } from '../../utils'

/** Description of an input */
const Input = React.forwardRef(function Input({ invalid, css, ...props }, ref) {
const Input = React.forwardRef(function Input({ fullWidth, invalid, css, ...props }, ref) {
let width = fullWidth ? '100%' : 'auto'

return (
<Element
ref={ref}
as="input"
component="Input"
aria-invalid={invalid}
css={merge(styles.Input, css)}
css={merge(styles.Input, { width }, css)}
{...props}
/>
)
})

Input.propTypes = {
/** Description of an input prop */
fullWidth: PropTypes.bool,
type: PropTypes.string
}

Expand Down
10 changes: 7 additions & 3 deletions packages/react-ui/src/components/select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ const usePlaceholder = props => {
return { placeholderStyles, onChange }
}

const Select = React.forwardRef(function Select({ css, ...props }, ref) {
const Select = React.forwardRef(function Select({ fullWidth, css, ...props }, ref) {
const { placeholderStyles, onChange } = usePlaceholder(props)
let width = fullWidth ? '100%' : 'auto'

return (
<Input
ref={ref}
as="select"
component="Select"
css={merge(merge(styles.Select, placeholderStyles), css)}
css={merge(merge(styles.Select, placeholderStyles), { width }, css)}
{...props}
onChange={mergeFns(onChange, props.onChange)}
/>
)
})

Select.propTypes = {}
Select.propTypes = {
/** Description of an select prop */
fullWidth: PropTypes.bool
}

Select.defaultProps = {}

Expand Down
7 changes: 5 additions & 2 deletions packages/react-ui/src/components/textarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import { styles } from './textarea.styles'
import { Input } from '../input'
import { merge } from '../../utils'

const Textarea = React.forwardRef(function Textarea({ css, ...props }, ref) {
const Textarea = React.forwardRef(function Textarea({ fullWidth, css, ...props }, ref) {
let width = fullWidth ? '100%' : 'auto'

return (
<Input
ref={ref}
as="textarea"
css={merge(styles.Textarea, css)}
css={merge(styles.Textarea, { width }, css)}
component="Textarea"
{...props}
/>
)
})

Textarea.propTypes = {
fullWidth: PropTypes.bool,
rows: PropTypes.number
}

Expand Down