Skip to content

Commit

Permalink
Towards CSS-based layout for ListField. Not very good.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTaylor committed Jan 19, 2024
1 parent a2a5283 commit a57a102
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/components/ListField.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.row {
display: flex;
justify-content: space-between; /* Can be changed in the live sample */
}

.field {
width: 70%
}
14 changes: 8 additions & 6 deletions src/components/ListField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { FormattedMessage } from 'react-intl';
import { Field } from 'react-final-form';
import { FieldArray } from 'react-final-form-arrays';
import { Row, Col, TextField, Label, IconButton, Button } from '@folio/stripes/components';
import css from './ListField.css';


const ListField = ({ name, label, renderEntry, component, emptyValue }) => {
return (
Expand All @@ -13,19 +15,19 @@ const ListField = ({ name, label, renderEntry, component, emptyValue }) => {
{({ fields }) => (
<>
{fields.map((subname, index) => (
<Row>
<Col xs={8}>
<div key={index} className={css.row}>
<div className={css.field}>
{renderEntry ?
renderEntry(subname) :
<Field name={subname} component={component || TextField} />
}
</Col>
<Col xs={4}>
</div>
<div>
<IconButton icon="arrow-up" disabled={index === 0} onClick={() => fields.swap(index - 1, index)} />
<IconButton icon="arrow-down" disabled={index === fields.length - 1} onClick={() => fields.swap(index, index + 1)} />
<IconButton icon="trash" onClick={() => fields.remove(index)} />
</Col>
</Row>
</div>
</div>
))}
<Button onClick={() => fields.push(emptyValue || '')}>
<FormattedMessage id="ui-harvester-admin.add" />
Expand Down

0 comments on commit a57a102

Please sign in to comment.