-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add padding for icon on Select, add SelectField, add docs * wip. include in docs * wip
- Loading branch information
1 parent
7630a53
commit 87c3090
Showing
8 changed files
with
210 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<Select onChange={(event) => alert(event.target.value)}> | ||
<option value="foo" checked>Foo</option> | ||
<option value="bar">Bar</option> | ||
</Select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react' | ||
import Box from 'ui-box' | ||
import Component from '@reactions/component' | ||
import Select from '../src/Select' | ||
|
||
/* eslint-disable import/no-unresolved, import/no-webpack-loader-syntax */ | ||
import sourceSelect from '!raw-loader!../src/Select' | ||
/* eslint-enable import/no-unresolved, import/no-webpack-loader-syntax */ | ||
|
||
/** | ||
* Code examples | ||
*/ | ||
import exampleSelectBasic from './examples/Select-basic.example' | ||
|
||
const title = 'Select' | ||
const subTitle = 'A styled native <select> for choosing items from a list.' | ||
|
||
const introduction = ( | ||
<div> | ||
<p> | ||
The <code>Select</code> component is a styled wrapper around a native{' '} | ||
<code>select</code> element, which allows selection of one item from a | ||
dropdown list. Anytime you would reach for a native select, use this. | ||
</p> | ||
</div> | ||
) | ||
|
||
const appearanceOptions = null | ||
|
||
const scope = { | ||
Box, | ||
Select, | ||
Component | ||
} | ||
|
||
const components = [ | ||
{ | ||
name: 'Select', | ||
source: sourceSelect, | ||
description: ( | ||
<p> | ||
The <code>Select</code> component. | ||
</p> | ||
), | ||
examples: [ | ||
{ | ||
title: 'Basic Select Example', | ||
description: ( | ||
<div> | ||
<p>This example shows basic usage with a selected item.</p> | ||
</div> | ||
), | ||
codeText: exampleSelectBasic, | ||
scope | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default { | ||
title, | ||
subTitle, | ||
introduction, | ||
appearanceOptions, | ||
components | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export Select from './src/Select' | ||
export SelectField from './src/SelectField' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { splitBoxProps } from 'ui-box' | ||
import { FormField } from '../../form-field' | ||
import Select from './Select' | ||
|
||
let idCounter = 0 | ||
|
||
export default class TextInputField extends PureComponent { | ||
static propTypes = { | ||
/** | ||
* Composes the Select component as the base. | ||
*/ | ||
...Select.propTypes, | ||
...FormField.propTypes, | ||
|
||
/** | ||
* The label used above the input element. | ||
*/ | ||
label: PropTypes.node.isRequired, | ||
|
||
/** | ||
* Passed on the label as a htmlFor prop. | ||
*/ | ||
labelFor: PropTypes.string, | ||
|
||
/** | ||
* Wether or not show a asterix after the label. | ||
*/ | ||
isRequired: PropTypes.bool, | ||
|
||
/** | ||
* A optional description of the field under the label, above the input element. | ||
*/ | ||
description: PropTypes.node, | ||
|
||
/** | ||
* A optional hint under the input element. | ||
*/ | ||
hint: PropTypes.node, | ||
|
||
/** | ||
* If a validation message is passed it is shown under the input element | ||
* and above the hint. | ||
*/ | ||
validationMessage: PropTypes.node, | ||
|
||
/** | ||
* The height of the input element. | ||
*/ | ||
inputHeight: PropTypes.number, | ||
|
||
/** | ||
* The width of the input width. | ||
*/ | ||
inputWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]) | ||
} | ||
|
||
static defaultProps = { | ||
/** | ||
* The input width should be as wide as the form field. | ||
*/ | ||
inputWidth: '100%', | ||
inputHeight: 32 | ||
} | ||
|
||
state = { | ||
id: (this.props.id || idCounter++).toString() | ||
} | ||
|
||
render() { | ||
const { | ||
// We are using the id from the state | ||
id: unusedId, | ||
|
||
// FormField props | ||
hint, | ||
label, | ||
description, | ||
validationMessage, | ||
|
||
// TextInput props | ||
inputHeight, | ||
inputWidth, | ||
disabled, | ||
required, | ||
isInvalid, | ||
appearance, | ||
|
||
// Rest props are spread on the FormField | ||
...props | ||
} = this.props | ||
|
||
const id = `SelectField-${this.state.id}` | ||
|
||
/** | ||
* Split the wrapper props from the input props. | ||
*/ | ||
const { matchedProps, remainingProps } = splitBoxProps(props) | ||
|
||
return ( | ||
<FormField | ||
marginBottom={24} | ||
label={label} | ||
isRequired={required} | ||
hint={hint} | ||
description={description} | ||
validationMessage={validationMessage} | ||
labelFor={id} | ||
{...matchedProps} | ||
> | ||
<Select | ||
id={id} | ||
width={inputWidth} | ||
height={inputHeight} | ||
disabled={disabled} | ||
required={required} | ||
isInvalid={isInvalid} | ||
appearance={appearance} | ||
{...remainingProps} | ||
/> | ||
</FormField> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters