Skip to content

Commit

Permalink
feat: add InputGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zivolo committed Jan 2, 2019
1 parent 353f254 commit ccf13be
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ exports[`renders a Button with small size 1`] = `
font-weight: bold;
display: inline-block;
border-radius: 2px;
line-height: 1.9;
height: 24px;
padding-left: 0.769em;
padding-right: 0.769em;
-webkit-transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
color: #121212;
border: 1px solid transparent;
background-color: #1ED7D1;
}
Expand Down Expand Up @@ -85,12 +86,13 @@ exports[`renders a disabled and transparent Button 1`] = `
font-weight: bold;
display: inline-block;
border-radius: 2px;
line-height: 2.3;
height: 32px;
padding-left: 0.769em;
padding-right: 0.769em;
-webkit-transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
color: #121212;
border: 1px solid transparent;
background-color: #1ED7D1;
cursor: default;
background-color: transparent;
Expand Down Expand Up @@ -163,12 +165,13 @@ exports[`renders the expected markup 1`] = `
font-weight: bold;
display: inline-block;
border-radius: 2px;
line-height: 2.3;
height: 32px;
padding-left: 0.769em;
padding-right: 0.769em;
-webkit-transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
transition: padding 0.2s ease-in-out,background 0.2s ease-in-out;
color: #121212;
border: 1px solid transparent;
background-color: #1ED7D1;
}
Expand Down
8 changes: 7 additions & 1 deletion packages/react-core/src/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const OKAY = '#039849';
const WARNING = '#FFCE03';
const HAZARD = '#E61E27';

const HEIGHT = {
small: 24,
regular: 32,
};

export type Importance =
| 'primary'
| 'secondary'
Expand Down Expand Up @@ -80,11 +85,12 @@ const Button = styled(
${textStyles('normal', 'bold')}
display: inline-block;
border-radius: 2px;
line-height: ${props => (props.size === 'small' ? 1.9 : 2.3)};
height: ${props => HEIGHT[props.size]}px;
padding-left: 0.769em;
padding-right: 0.769em;
transition: padding 0.2s ease-in-out, background 0.2s ease-in-out;
color: ${wf(props => props.theme.colors.black)};
border: 1px solid transparent;
${wf(props => {
const variations = {
Expand Down
1 change: 1 addition & 0 deletions packages/react-forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@quid/react-core": "^1.11.0",
"@quid/theme": "^1.11.0",
"color": "^3.1.0",
"emotion": "^10.0.5",
"react": "^16.7.0",
"react-router-dom": "^4.3.1"
},
Expand Down
36 changes: 36 additions & 0 deletions packages/react-forms/src/InputGroup/InputGroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
The `InputGroup` component takes N children elements and adjusts their
`border-radius` CSS property according to their order in the parent.

The first element will lose any eventual rigth `border-radius`, any element
in the middle will lose `border-radius` on both sides, and the last element
will lose `border-radius` on its left.

```js
<InputGroup>
<InputText placeholder="InputText" />
<Button importance="secondary">Button</Button>
</InputGroup>
```

The above method will automatically inject the `className`, if this behavior is
not desired, a render-prop can be passed, with the `className` as first argument.

```js
<InputGroup>
{className => <InputText className={className} placeholder="InputText" />}
{className => (
<Button importance="secondary" className={className}>
Button
</Button>
)}
</InputGroup>
```

You can combine any of the components exported by `@quid/react-forms`:

```js
<InputGroup>
<Button>Btn</Button>
<InputNumber />
</InputGroup>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`applies the expected class names 1`] = `
.emotion-3 {
display: inline-block;
border-radius: 2px;
-webkit-transition: 0.2s ease-in-out border-color;
transition: 0.2s ease-in-out border-color;
border: 1px solid #8F9BA3;
}
.emotion-3:focus-within {
border-color: #00c1bb;
}
.emotion-0 {
border-radius: 1px 0 0 1px;
border-left: 0;
border-top: 0;
border-bottom: 0;
}
.emotion-1 {
border-radius: 0;
border-top: 0;
border-bottom: 0;
}
.emotion-2 {
border-radius: 0 1px 1px 0;
border-right: 0;
border-top: 0;
border-bottom: 0;
}
<InputGroup>
<div
className="emotion-3 emotion-4"
>
<span
className="emotion-0"
key=".$.0"
/>
<span
className="emotion-1"
key=".$.1"
/>
<span
className="emotion-2"
key=".$.2"
/>
</div>
</InputGroup>
`;
61 changes: 61 additions & 0 deletions packages/react-forms/src/InputGroup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @flow
import * as React from 'react';
import { css } from 'emotion';
import styled from '@emotion/styled/macro';
import { withFallback as wf } from '@quid/theme';

const toArray = (children): Array<React.Element<any> | Function> =>
React.Children.toArray(children).length
? React.Children.toArray(children)
: Array.isArray(children)
? children
: [];

type Props = {
children: React.Node,
className?: ?string,
};

const InputGroup = styled(({ children, className, ...props }: Props) => (
<div className={className}>
{React.Children.toArray(
toArray(children).map((child, i) => {
const className =
i === 0
? css`
border-radius: 1px 0 0 1px;
border-left: 0;
border-top: 0;
border-bottom: 0;
`
: i === toArray(children).length - 1
? css`
border-radius: 0 1px 1px 0;
border-right: 0;
border-top: 0;
border-bottom: 0;
`
: css`
border-radius: 0;
border-top: 0;
border-bottom: 0;
`;

return typeof child === 'function'
? child(className)
: React.cloneElement(child, { className });
})
)}
</div>
))`
display: inline-block;
border-radius: 2px;
transition: 0.2s ease-in-out border-color;
border: 1px solid ${wf(props => props.theme.colors.gray3)};
&:focus-within {
border-color: ${wf(props => props.theme.colors.selected)};
}
`;

// @component
export default InputGroup;
30 changes: 30 additions & 0 deletions packages/react-forms/src/InputGroup/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow
import * as React from 'react';
import { mount } from 'enzyme';
import InputGroup from '.';

it('provides the expected class names', () => {
mount(
<InputGroup>
{cn => expect(cn).toMatchInlineSnapshot(`"css-eklp95"`)}
{cn => expect(cn).toMatchInlineSnapshot(`"css-1ts4n50"`)}
{cn => expect(cn).toMatchInlineSnapshot(`"css-cesvsp"`)}
</InputGroup>
);
});

it('applies the expected class names', () => {
expect(
mount(
<InputGroup>
<span />
<span />
<span />
</InputGroup>
)
).toMatchSnapshot();
});

it("doesn't explodes on unexpected children", () => {
mount(<InputGroup />);
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`renders the expected markup 1`] = `
font-family: IBM Plex Sans,Lucida Grande,Tahoma,Verdana,Arial,sans-serif;
font-size: 14px;
line-height: 1.57;
vertical-align: top;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -26,7 +27,7 @@ exports[`renders the expected markup 1`] = `
transition: border 0.2s ease-in-out;
border-radius: 2px;
padding: 0 10px;
height: 30px;
height: 32px;
background-color: #FFFFFF;
color: #121212;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-forms/src/InputText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const INPUT_ATTRIBUTES = [
const HEIGHT = {
large: 50,
small: 24,
regular: 30,
regular: 32,
};

const PADDING = {
Expand Down Expand Up @@ -109,6 +109,7 @@ const Input = styled.input`

const Container = styled.div`
${textStyles('normal')}
vertical-align: top;
display: inline-flex;
align-items: center;
Expand Down
47 changes: 46 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,17 @@
"@emotion/utils" "0.11.1"
csstype "^2.5.7"

"@emotion/serialize@^0.11.3":
version "0.11.3"
resolved "https://registry.npmjs.org/@emotion/serialize/-/serialize-0.11.3.tgz#c4af2d96e3ddb9a749b7b567daa7556bcae45af2"
integrity sha512-6Q+XH/7kMdHwtylwZvdkOVMydaGZ989axQ56NF7urTR7eiDMLGun//pFUy31ha6QR4C6JB+KJVhZ3AEAJm9Z1g==
dependencies:
"@emotion/hash" "0.7.1"
"@emotion/memoize" "0.7.1"
"@emotion/unitless" "0.7.3"
"@emotion/utils" "0.11.1"
csstype "^2.5.7"

"@emotion/sheet@0.9.2":
version "0.9.2"
resolved "https://registry.npmjs.org/@emotion/sheet/-/sheet-0.9.2.tgz#74e5c6b5e489a1ba30ab246ab5eedd96916487c4"
Expand Down Expand Up @@ -2618,6 +2629,22 @@ babel-plugin-emotion@^10.0.4:
find-root "^1.1.0"
source-map "^0.5.7"

babel-plugin-emotion@^10.0.5:
version "10.0.5"
resolved "https://registry.npmjs.org/babel-plugin-emotion/-/babel-plugin-emotion-10.0.5.tgz#05ec47cde94f984b0b2aebdd41f81876cf9cbb24"
integrity sha512-ezct2vKACg4juSV0/A/4QIDJu2+5Sjna/8rX/LXY8D0qG8YEP3fu8pe5FqZ9yFGa8WOJ1sivf3/QKM/5C8naIg==
dependencies:
"@babel/helper-module-imports" "^7.0.0"
"@emotion/hash" "0.7.1"
"@emotion/memoize" "0.7.1"
"@emotion/serialize" "^0.11.3"
babel-plugin-macros "^2.0.0"
babel-plugin-syntax-jsx "^6.18.0"
convert-source-map "^1.5.0"
escape-string-regexp "^1.0.5"
find-root "^1.1.0"
source-map "^0.5.7"

babel-plugin-istanbul@^4.1.6:
version "4.1.6"
resolved "http://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45"
Expand Down Expand Up @@ -4096,6 +4123,16 @@ create-ecdh@^4.0.0:
bn.js "^4.1.0"
elliptic "^6.0.0"

create-emotion@^10.0.5:
version "10.0.5"
resolved "https://registry.npmjs.org/create-emotion/-/create-emotion-10.0.5.tgz#22487f19b59a7ed10144f808289eadffebcfab06"
integrity sha512-MIOSeFiMtPrAULEtd2GFYGZEzeN2xnCFoiHrjvUYjxruYCJfGqUOBmh4YEN1yU+Ww5yXr+DIZibFl7FEOP57iA==
dependencies:
"@emotion/cache" "10.0.0"
"@emotion/serialize" "^0.11.3"
"@emotion/sheet" "0.9.2"
"@emotion/utils" "0.11.1"

create-hash@^1.1.0, create-hash@^1.1.2:
version "1.2.0"
resolved "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz#889078af11a63756bcfb59bd221996be3a9ef196"
Expand Down Expand Up @@ -5009,6 +5046,14 @@ emotion-theming@^10.0.2:
hoist-non-react-statics "^2.3.1"
object-assign "^4.1.1"

emotion@^10.0.5:
version "10.0.5"
resolved "https://registry.npmjs.org/emotion/-/emotion-10.0.5.tgz#9b22cee820de0a45bc102e4750553c1b81098b00"
integrity sha512-bYti4oM6k1oDm/qZ3w/AcJNJDitTt++/EWy9TqYu2Th7YEJw2H5hesihynHszsfn4TAf5TS43y+51/KWHFnuBA==
dependencies:
babel-plugin-emotion "^10.0.5"
create-emotion "^10.0.5"

encodeurl@~1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
Expand Down Expand Up @@ -8975,7 +9020,7 @@ methods@~1.1.2:
resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=

microbundle@^0.8.3, "microbundle@https://github.com/FezVrasta/microbundle.git#quid-fork":
microbundle@^0.8.3:
version "0.8.3"
resolved "https://github.com/FezVrasta/microbundle.git#834297a3134eaf24e0cc35da60812a53b2aef96b"
dependencies:
Expand Down

0 comments on commit ccf13be

Please sign in to comment.