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

feat(text-input): adds fluid variation of text input #5830

Merged
merged 34 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
784e9d9
feat(text-inputs): adds fluid variation of text input
Apr 9, 2020
ed1adaa
feat(text-input): add fluid to props
Apr 9, 2020
e1d7c20
Merge branch 'master' into fluid-inputs
tw15egan Apr 13, 2020
f51cbec
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Apr 14, 2020
c1a66a1
Merge branch 'fluid-inputs' of github.com:aledavila/carbon into fluid…
Apr 14, 2020
2be7124
feat(form): adds fluid prop to form component
Apr 14, 2020
a8a2167
chore(text-input): move fluid handling to form
Apr 14, 2020
e90c83b
Merge branch 'master' into fluid-inputs
tw15egan Apr 14, 2020
cb43076
feat(FluidForm): add fluid form component
tw15egan Apr 14, 2020
16c9268
Merge pull request #1 from tw15egan/fluid-form-addition
aledavila Apr 15, 2020
f43d595
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Apr 16, 2020
71f76c2
feat(text-input): add fluid error state
Apr 16, 2020
fc67b0c
chore(text-input): update invalid state css
Apr 16, 2020
5f16f6d
feat(fluid-input): add context to fluid form
tw15egan Apr 17, 2020
4ffb1b7
Merge pull request #2 from tw15egan/fluid-form-context
aledavila Apr 20, 2020
05a3859
Merge branch 'master' into fluid-inputs
tw15egan Apr 20, 2020
5daa6c1
Merge branch 'master' into fluid-inputs
aagonzales Apr 20, 2020
08a11d8
Merge branch 'master' into fluid-inputs
aledavila Apr 20, 2020
0085f01
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Apr 21, 2020
06ef857
Merge branch 'fluid-inputs' of github.com:aledavila/carbon into fluid…
Apr 21, 2020
9a3f8a6
chore(fluid-form): remove button from storybook and margin from fluid
Apr 21, 2020
37f91c2
Merge branch 'master' into fluid-inputs
tw15egan Apr 22, 2020
e48050c
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Apr 22, 2020
3f462d6
chore(text-input): css fixes
Apr 22, 2020
3fb44d4
Merge branch 'master' into fluid-inputs
tw15egan Apr 23, 2020
d9f82f0
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Apr 27, 2020
d4e4129
Merge branch 'fluid-inputs' of github.com:aledavila/carbon into fluid…
Apr 27, 2020
4c335c3
chore(text-input): make divider conditional
Apr 27, 2020
d800c80
Merge branch 'master' into fluid-inputs
tw15egan Apr 28, 2020
e083e9a
chore(text-input): update snapshots
Apr 28, 2020
b347764
Merge branch 'master' into fluid-inputs
joshblack Apr 29, 2020
132a724
Merge branch 'master' into fluid-inputs
Apr 29, 2020
0971805
Merge branch 'master' into fluid-inputs
Apr 29, 2020
13b93d9
Merge branch 'master' into fluid-inputs
Apr 29, 2020
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
20 changes: 20 additions & 0 deletions packages/components/src/components/form/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@
}
}

//Fluid Form
.#{$prefix}--form--fluid
.#{$prefix}--text-input__field-wrapper[data-invalid] {
display: block;
}

.#{$prefix}--form--fluid .#{$prefix}--fieldset {
margin: 0;
}

.#{$prefix}--form--fluid input[data-invalid] {
outline: none;
}

.#{$prefix}--form--fluid .#{$prefix}--form-requirement {
margin: 0;
padding: $carbon--spacing-03 rem(40px) $carbon--spacing-03
$carbon--spacing-05;
}

// Fix for red ring when input is marked required in Firefox, refs #744
input:not(output):not([data-invalid]):-moz-ui-invalid {
box-shadow: none;
Expand Down
54 changes: 54 additions & 0 deletions packages/components/src/components/text-input/_text-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,60 @@
right: $carbon--spacing-08;
}
}

//-----------------------------
// Fluid Text Input
//-----------------------------
.#{$prefix}--form--fluid .#{$prefix}--text-input-wrapper {
position: relative;
background: $field-01;
transition: background-color $duration--fast-01 motion(standard, productive),
outline $duration--fast-01 motion(standard, productive);
}

.#{$prefix}--form--fluid .#{$prefix}--label {
position: absolute;
top: rem(13px);
left: $carbon--spacing-05;
z-index: 1;
margin: 0;
}

.#{$prefix}--form--fluid .#{$prefix}--form__helper-text {
display: none;
}

.#{$prefix}--form--fluid .#{$prefix}--text-input {
min-height: rem(64px);
padding: rem(32px) $carbon--spacing-05 rem(13px);
}

.#{$prefix}--text-input__divider,
.#{$prefix}--form--fluid .#{$prefix}--text-input__divider {
display: none;
}

.#{$prefix}--form--fluid .#{$prefix}--text-input--invalid {
border-bottom: none;
}

.#{$prefix}--form--fluid
.#{$prefix}--text-input--invalid
+ .#{$prefix}--text-input__divider {
display: block;
margin: 0 1rem;
border-style: solid;
border-bottom: none;
border-color: $ui-03;
}

.#{$prefix}--form--fluid .#{$prefix}--text-input__invalid-icon {
top: rem(80px);
}

.#{$prefix}--form--fluid .#{$prefix}--text-input-wrapper--light {
background: $field-02;
}
}

@include exports('text-input') {
Expand Down
10 changes: 10 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,16 @@ Map {
},
},
},
"FluidForm" => Object {
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
},
},
"FormGroup" => Object {
"defaultProps": Object {
"invalid": false,
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('Carbon Components React', () => {
"FileUploaderItem",
"FileUploaderSkeleton",
"Filename",
"FluidForm",
"Form",
"FormGroup",
"FormItem",
Expand Down
67 changes: 67 additions & 0 deletions packages/react/src/components/FluidForm/FluidForm-story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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 { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { withKnobs } from '@storybook/addon-knobs';
import FluidForm from '../FluidForm';
import TextInput from '../TextInput';

const additionalProps = {
className: 'some-class',
onSubmit: e => {
e.preventDefault();
action('FormSubmitted')(e);
},
};

const TextInputProps = {
className: 'some-class',
id: 'test2',
labelText: 'Text Input label',
placeholder: 'Placeholder text',
};

const InvalidPasswordProps = {
className: 'some-class',
id: 'test4',
labelText: 'Password',
invalid: true,
invalidText:
'Your password must be at least 6 characters as well as contain at least one uppercase, one lowercase, and one number.',
};

storiesOf('FluidForm', module)
.addDecorator(withKnobs)
.add(
'Default',
() => (
<FluidForm {...additionalProps}>
<TextInput {...TextInputProps} />

<TextInput
type="password"
required
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}"
{...InvalidPasswordProps}
/>
</FluidForm>
),
{
info: {
text: `
Forms are widely used to collect user input.

Form can have any number of react components enclosed within FormGroup component. FormGroup component
is a wrapper for legend and fieldset component.

`,
},
}
);
58 changes: 58 additions & 0 deletions packages/react/src/components/FluidForm/FluidForm-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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 FluidForm from '../FluidForm';
import { shallow, mount } from 'enzyme';

describe('FluidForm', () => {
describe('Renders as expected', () => {
const wrapper = mount(<FluidForm className="extra-class" />);
it('renders children as expected', () => {
expect(wrapper.find('.child').length).toBe(0);
});
it('renders wrapper as expected', () => {
expect(wrapper.length).toBe(1);
});
it('renders extra classes passed in via className', () => {
expect(wrapper.hasClass('extra-class')).toEqual(true);
});

it('should render wrapper as expected', () => {
const form = shallow(
<FluidForm>
<div className="test-child1" />
<div className="test-child2" />
</FluidForm>
);
expect(form.length).toEqual(1);
});
it('should render children as expected', () => {
const form1 = shallow(
<FluidForm>
<div className="test-child" />
<div className="test-child" />
</FluidForm>
);
expect(form1.find('.test-child').length).toBe(2);
});

it('should handle submit events', () => {
const onSubmit = jest.fn();
const form1 = mount(
<FluidForm>
<button className="button" type="submit" onSubmit={onSubmit}>
Submit
</button>
</FluidForm>
);
const btn = form1.find('button');
btn.simulate('submit');
expect(onSubmit).toBeCalled();
});
});
});
41 changes: 41 additions & 0 deletions packages/react/src/components/FluidForm/FluidForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 classnames from 'classnames';
import { settings } from 'carbon-components';
import Form from '../Form';
import { FormContext } from './FormContext';

const { prefix } = settings;

function FluidForm({ className, children, ...other }) {
joshblack marked this conversation as resolved.
Show resolved Hide resolved
const classNames = classnames(`${prefix}--form--fluid`, className);

return (
<FormContext.Provider value={{ isFluid: true }}>
<Form className={classNames} {...other}>
{children}
</Form>
</FormContext.Provider>
);
}

FluidForm.propTypes = {
/**
* Provide children to be rendered inside of the <form> element
*/
children: PropTypes.node,

/**
* Provide a custom className to be applied on the containing <form> node
*/
className: PropTypes.string,
};

export default FluidForm;
12 changes: 12 additions & 0 deletions packages/react/src/components/FluidForm/FormContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* 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 { createContext } from 'react';

export const FormContext = createContext({
isFluid: false,
});
9 changes: 9 additions & 0 deletions packages/react/src/components/FluidForm/index.js
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 './FluidForm';
export { FormContext } from './FormContext';
1 change: 0 additions & 1 deletion packages/react/src/components/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const { prefix } = settings;

const Form = ({ className, children, ...other }) => {
const classNames = classnames(`${prefix}--form`, className);

return (
<form className={classNames} {...other}>
{' '}
Expand Down
22 changes: 22 additions & 0 deletions packages/react/src/components/TextInput/TextInput-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { action } from '@storybook/addon-actions';
import { withKnobs, boolean, select, text } from '@storybook/addon-knobs';
import TextInput from '../TextInput';
import TextInputSkeleton from '../TextInput/TextInput.Skeleton';
import FluidForm from '../FluidForm/FluidForm';

const types = {
None: '',
Expand Down Expand Up @@ -114,6 +115,27 @@ storiesOf('TextInput', module)
},
}
)
.add(
'Fluid',
() => (
<FluidForm>
<TextInput
type={select('Form control type (type)', types, 'text')}
{...props.TextInputProps()}
/>
</FluidForm>
),
{
info: {
text: `
Text fields enable the user to interact with and input data. A single line
field is used when the input anticipated by the user is a single line of
text as opposed to a paragraph.
The default type is 'text' and its value can be either 'string' or 'number'.
`,
},
}
)
.add(
'Toggle password visibility',
() => {
Expand Down
Loading