Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Converted InputGroup.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Mar 6, 2017
1 parent 26039b1 commit 2217f30
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 58 deletions.
9 changes: 3 additions & 6 deletions src/components/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ export default class BaseInput extends React.Component {
inputProps.checked = state.checked;
inputProps.multiple = props.multiple;

if (
!props.id &&
(props.multiple || props.type === 'radio') &&
typeof state.value === 'string'
) {
inputProps.id += `-${state.value}`;
if (!props.id && (props.multiple || props.type === 'radio')) {
// $FlowIgnore We know these are strings
inputProps.id = `${inputProps.id}-${state.value}`;
}

// eslint-disable-next-line no-fallthrough
Expand Down
61 changes: 35 additions & 26 deletions src/components/InputGroup/Addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@
* @copyright 2010-2017, The Titon Project
* @license http://opensource.org/licenses/BSD-3-Clause
* @link http://titon.io
* @flow
*/

import React, { PropTypes } from 'react';
import Component from '../../Component';
import { defaultSizeProps, sizePropTypes } from '../../propTypes';
import MODULE from './module';
import style, { classes } from '../../styler';
import { classNamesPropType, sizeDefaults, sizePropTypes } from '../../propTypes';

export default class Addon extends Component {
static module = MODULE;
import type { InputGroupAddonProps } from './types';

static defaultProps = {
...defaultSizeProps,
};
export function ToolkitInputGroupAddon({
children,
classNames,
large,
small,
}: InputGroupAddonProps) {
return (
<span
className={classes(classNames.addon, {
[classNames.addon__large]: large,
[classNames.addon__small]: small,
})}
>
{children}
</span>
);
}

static propTypes = {
...sizePropTypes,
children: PropTypes.node,
};
ToolkitInputGroupAddon.propTypes = {
...sizePropTypes,
children: PropTypes.node,
classNames: classNamesPropType.isRequired,
};

render() {
const props = this.props;
ToolkitInputGroupAddon.defaultProps = {
...sizeDefaults,
children: null,
};

return (
<span
className={this.formatChildClass('addon', {
'@large': props.large,
'@small': props.small,
})}
>
{props.children}
</span>
);
}
}
export default style({
addon: 'input-group__addon',
addon__large: 'input-group__addon--large',
addon__small: 'input-group__addon--small',
})(ToolkitInputGroupAddon);
34 changes: 20 additions & 14 deletions src/components/InputGroup/InputGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
* @copyright 2010-2017, The Titon Project
* @license http://opensource.org/licenses/BSD-3-Clause
* @link http://titon.io
* @flow
*/

import React from 'react';
import Component from '../../Component';
import MODULE from './module';
import React, { PropTypes } from 'react';
import style, { classes } from '../../styler';
import { classNamesPropType } from '../../propTypes';

export default class InputGroup extends Component {
static module = MODULE;
import type { InputGroupProps } from './types';

render() {
const props = this.props;

return (
<span className={this.formatClass()}>
{props.children}
</span>
);
}
export function ToolkitInputGroup({ children, classNames }: InputGroupProps) {
return (
<span className={classes(classNames.inputGroup)}>
{children}
</span>
);
}

ToolkitInputGroup.propTypes = {
children: PropTypes.node.isRequired,
classNames: classNamesPropType.isRequired,
};

export default style({
inputGroup: 'input-group',
})(ToolkitInputGroup);
12 changes: 0 additions & 12 deletions src/components/InputGroup/module.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/components/InputGroup/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @copyright 2010-2017, The Titon Project
* @license http://opensource.org/licenses/BSD-3-Clause
* @link http://titon.io
* @flow
*/

import type { ReactChildren, ClassNameMap } from '../../types';

export type InputGroupProps = {
children: ReactChildren,
classNames: ClassNameMap,
};

export type InputGroupAddonProps = {
children: ReactChildren,
classNames: ClassNameMap,
large: boolean,
small: boolean,
};

0 comments on commit 2217f30

Please sign in to comment.