Skip to content

Commit

Permalink
Added custom ListField icons in bootstrap3.
Browse files Browse the repository at this point in the history
  • Loading branch information
todda00 authored and radekmie committed Oct 19, 2016
1 parent 2b146e2 commit 965a862
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {connectField} from 'uniforms';
import {filterDOMProps} from 'uniforms';

const ListAdd = ({
addIcon,
className,
disabled,
parent,
Expand All @@ -18,10 +19,13 @@ const ListAdd = ({
onClick={() => limitNotReached && parent.onChange(parent.value.concat([value]))}
{...filterDOMProps(props)}
>
{/* TODO: configure to alternate icon */}
<i className="glyphicon glyphicon-plus" />
{addIcon}
</section>
);
};

ListAdd.defaultProps = {
addIcon: <i className="glyphicon glyphicon-plus" />
};

export default connectField(ListAdd, {includeParent: true, initialValue: false});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ListDel = ({
disabled,
name,
parent,
removeIcon,
...props
}) => {
const fieldIndex = +name.slice(1 + name.lastIndexOf('.'));
Expand All @@ -22,10 +23,13 @@ const ListDel = ({
)}
{...filterDOMProps(props)}
>
{/* TODO: configure to alternate icon */}
<i className="glyphicon glyphicon-minus" />
{removeIcon}
</span>
);
};

ListDel.defaultProps = {
removeIcon: <i className="glyphicon glyphicon-minus" />
};

export default connectField(ListDel, {includeParent: true, initialValue: false});
15 changes: 12 additions & 3 deletions packages/uniforms-bootstrap3/src/components/fields/ListField.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import ListAddField from './ListAddField';
import ListItemField from './ListItemField';

const List = ({
addIcon,
children,
className,
error,
initialCount,
itemProps,
label,
name,
removeIcon,
value,
...props
}) =>
Expand All @@ -30,7 +32,7 @@ const List = ({
{label}&nbsp;
</label>

<ListAddField name={`${name}.$`} initialCount={initialCount} />
<ListAddField name={`${name}.$`} initialCount={initialCount} addIcon={addIcon} />
</section>
)}

Expand All @@ -40,13 +42,20 @@ const List = ({
React.cloneElement(child, {
key: index,
label: null,
name: joinName(name, child.props.name && child.props.name.replace('$', index))
name: joinName(name, child.props.name && child.props.name.replace('$', index)),
removeIcon
})
)
)
) : (
value.map((item, index) =>
<ListItemField key={index} label={null} name={joinName(name, index)} {...itemProps} />
<ListItemField
key={index}
label={null}
name={joinName(name, index)}
removeIcon={removeIcon}
{...itemProps}
/>
)
)}
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ListDelField from './ListDelField';
const ListItem = props =>
<section className="row">
<section className="col-xs-1">
<ListDelField name={props.name} />
<ListDelField name={props.name} removeIcon={props.removeIcon} />
</section>

{props.children ? (
Expand Down

0 comments on commit 965a862

Please sign in to comment.