-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FluidTextInput): create FluidTextInput component
- Loading branch information
Showing
4 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
packages/react/src/components/FluidTextInput/FluidTextInput.js
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,91 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import FluidForm from '../FluidForm'; | ||
import TextInput from '../TextInput'; | ||
|
||
function FluidTextInput({ className, ...other }) { | ||
return ( | ||
<FluidForm className={className}> | ||
<TextInput {...other} /> | ||
</FluidForm> | ||
); | ||
} | ||
|
||
FluidTextInput.propTypes = { | ||
/** | ||
* Specify an optional className to be applied to the outer FluidForm wrapper | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Optionally provide the default value of the `<input>` | ||
*/ | ||
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
|
||
/** | ||
* Specify whether the `<input>` should be disabled | ||
*/ | ||
disabled: PropTypes.bool, | ||
|
||
/** | ||
* Specify a custom `id` for the `<input>` | ||
*/ | ||
id: PropTypes.string.isRequired, | ||
|
||
/** | ||
* Specify whether the control is currently invalid | ||
*/ | ||
invalid: PropTypes.bool, | ||
|
||
/** | ||
* Provide the text that is displayed when the control is in an invalid state | ||
*/ | ||
invalidText: PropTypes.node, | ||
|
||
/** | ||
* Provide the text that will be read by a screen reader when visiting this | ||
* control | ||
*/ | ||
labelText: PropTypes.node.isRequired, | ||
|
||
/** | ||
* Optionally provide an `onChange` handler that is called whenever `<input>` | ||
* is updated | ||
*/ | ||
onChange: PropTypes.func, | ||
|
||
/** | ||
* Optionally provide an `onClick` handler that is called whenever the | ||
* `<input>` is clicked | ||
*/ | ||
onClick: PropTypes.func, | ||
|
||
/** | ||
* Specify the placeholder attribute for the `<input>` | ||
*/ | ||
placeholder: PropTypes.string, | ||
|
||
/** | ||
* Specify the value of the `<input>` | ||
*/ | ||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
|
||
/** | ||
* Specify whether the control is currently in warning state | ||
*/ | ||
warn: PropTypes.bool, | ||
|
||
/** | ||
* Provide the text that is displayed when the control is in warning state | ||
*/ | ||
warnText: PropTypes.node, | ||
}; | ||
|
||
export default FluidTextInput; |
116 changes: 116 additions & 0 deletions
116
packages/react/src/components/FluidTextInput/FluidTextInput.stories.js
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,116 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import FluidTextInput from '../FluidTextInput'; | ||
import { | ||
ToggletipLabel, | ||
Toggletip, | ||
ToggletipButton, | ||
ToggletipContent, | ||
} from '../Toggletip'; | ||
import { Information } from '@carbon/icons-react'; | ||
|
||
export default { | ||
title: 'Components/FluidTextInput', | ||
component: FluidTextInput, | ||
}; | ||
|
||
export const Default = () => ( | ||
<FluidTextInput labelText="Label" placeholder="Placeholder text" /> | ||
); | ||
|
||
const ToggleTip = ( | ||
<> | ||
<ToggletipLabel>Label</ToggletipLabel> | ||
<Toggletip> | ||
<ToggletipButton label="Show information"> | ||
<Information /> | ||
</ToggletipButton> | ||
<ToggletipContent> | ||
<p>Additional field information here.</p> | ||
</ToggletipContent> | ||
</Toggletip> | ||
</> | ||
); | ||
|
||
export const DefaultWithTooltip = () => ( | ||
<FluidTextInput labelText={ToggleTip} placeholder="Placeholder text" /> | ||
); | ||
|
||
export const Playground = (args) => ( | ||
<div style={{ width: args.playgroundWidth }}> | ||
<FluidTextInput {...args} /> | ||
</div> | ||
); | ||
|
||
Playground.argTypes = { | ||
playgroundWidth: { | ||
control: { type: 'range', min: 300, max: 800, step: 50 }, | ||
defaultValue: 300, | ||
}, | ||
className: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: 'test-class', | ||
}, | ||
defaultValue: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
placeholder: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: 'Placeholder text', | ||
}, | ||
invalid: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
defaultValue: false, | ||
}, | ||
invalidText: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: | ||
'Error message that is really long can wrap to more lines but should not be excessively long.', | ||
}, | ||
disabled: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
defaultValue: false, | ||
}, | ||
labelText: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: 'Label', | ||
}, | ||
warn: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
defaultValue: false, | ||
}, | ||
warnText: { | ||
control: { | ||
type: 'text', | ||
}, | ||
defaultValue: | ||
'Warning message that is really long can wrap to more lines but should not be excessively long.', | ||
}, | ||
value: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
}; |
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,9 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export default from './FluidTextInput'; | ||
export { FluidTextInput } from './FluidTextInput'; |
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