$ cnpm install @up-group-ui/react-controls
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get started!
Clone the Repo git clone https://github.com/Up-Group/react-controls
Install Dependencies From the root of the project directory, run yarn
if you have yarn installed globally. --- or --- npm install
.
This project embraces styled-components as it's a fantastic way to style your React components.
Check the components directory for examples.
src/
│ ├── Input
│ │ ├── __tests__
│ │ │ ├── __mocks__
│ │ │ │ └── boxMocks.mock.ts
│ │ │ ├── __snapshots__
│ │ │ │ └── index.test.tsx.snap
│ │ │ └── index.test.tsx
│ │ ├── index.tsx
│ │ ├── styles.ts
| | ├── Input.tsx
| | └── ...
├── index.ts
Next to come
Included is a test framework for all of your React testing needs. We are using Jest to run the test suite and generate snapshots, plus Enzyme for component introspection.
Tests should be collocated within the component they represent. Test files should be named index.test.tsx
and mocks must be named myMock.mock.ts
.
npm run setup:yarn
npm install
npm run test
npm run test:watch
npm run test:update
Containers
Display
Inputs
Each input component has the common props :
onChange?: (arg: _BaseType, event: any) => void : the onChange handler
value?: _BaseType : the type of value
disabled?:boolean : the disable state of the component
readonly?:boolean : the readonly state of the component
tooltip?: string | Tooltip : a tooltip explaining the usage of the component
UpCheckbox : provide a component to display a set of option with multiple choice
A checkbox option is defined as : - name:string : the name attribute of the input DOMElement - value:any : the value of the input DOMElement - text?:string : the text to be displayed next to the checkbox - iconName?:string : a icon within the set provided by our UI kit - onChange?:(e:any) => void : the onChange handler - checked:boolean : the checked value of the checkbox
<UpCheckbox options={[{
text: "My Option 1",
name: "Option1",
onChange: this.onOptionChange,
value: true,
checked: this.state.option1 === true
}, {
text: "My Option 2",
name: "Option2",
onChange: this.onOptionChange,
value: true,
checked: this.state.option2 === true
}, {
text: "My Option 3",
name: "Option3",
onChange: this.onOptionChange,
value: true,
checked: this.state.option3 === true
}]} />
<UpLabel width="small" inline={true} text="Begin date :">
<UpDate tooltip="Start dat of ..." maxDate={this.state.endDate} onChange={this.onBeginDateChange} value={this.state.beginDate} />
</UpLabel>
<UpLabel width="small" inline={true} text="End date :">
<UpDate minDate={this.state.beginDate} onChange={this.onEndDateChange} value={this.state.endDate} />
</UpLabel>
<UpLabel inline={true} text="Date and time :">
<UpDateTime onChange={this.onDateTimeChange} value={this.state.dateTime} />
</UpLabel>
<UpLabel inline={true} text="Email :" textAlign="right" width="small">
<UpEmail width="xlarge" placeholder="Enter the email used for your identification" onChange={this.onEmailChange} value={this.state.email} />
</UpLabel>
UpFile
UpInput : a generic component for specifying single line text
<UpLabel text="Confirmation code :" inline={true} textAlign="right" width="small">
<UpInput width="xlarge" placeholder="Enter the confirmation code"
validation={[{
pattern:/^(\d){4}$/,
errorMessage:"Must contain 4 digits"
}]}
tooltip="The verification code received by SMS"
iconName="ok-sign"
maxLength={4}
value={this.state.code} />
</UpLabel>
<UpNumber width="xlarge" placeholder="Enter the amount"
stepSize={10} onChange={this.onAmountChange} decimalPlace={2}
tooltip="The amount of ..."
value={this.state.amout} />
<UpLabel text="Age :" inline={true} textAlign="right" width="small">
<UpInteger width="xlarge" placeholder="Entrer your age"
stepSize={10} onChange={this.onAgeChange}
value={this.state.age} />
</UpLabel>
<UpLabel inline={true} text="Phone :" textAlign="right" width="small">
<UpPhone width="xlarge" placeholder="Enter your phone number" onChange={this.onPhoneChange} value={this.state.phone} />
</UpLabel>
A checkbox option is defined as : - value:any : the value of the input DOMElement - text?:string : the text to be displayed next to the checkbox - iconName?:string : a icon within the set provided by our UI kit - onChange?:(e:any) => void : the onChange handler - checked:boolean : the checked value of the checkbox
<UpRadio name="gender" value={this.state.gender}
options={[{
text: "Female",
onChange: this.onGenderChange,
value: "F",
checked: this.state.gender === "F"
}, {
text: "Male",
onChange: this.onGenderChange,
value: "M",
checked: this.state.gender === "M"
}]} />
An UpSelectOption is defined as : id:number|string : the unique id of the option text:string: the text to be displayed icon:string : the icon to be displayed
<UpLabel inline={true} width="small" text="My todos :">
<UpSelect autoload={false}
allowClear={true}
multiple={false}
tooltip="Selct the todos completed"
minimumInputLength={3}
dataSource={{
query: "https://jsonplaceholder.typicode.com/todos",
text: "title"
}}
onError={this.onSelectionError} onChange={this.onSelectionChange} value={this.state.todosCompleted} />
</UpLabel>
UpText
UpTimePicker
See here for our contribution guide. We are on slack, please go [here for an invite] We'd love to hear from you!
See here for the license.
Copyright 2014 - 2017 © taobao.org |