This repository has been archived by the owner on Mar 29, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for literal contributor names. closes #215
- Loading branch information
Showing
10 changed files
with
234 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { action, observable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
|
||
import Button from 'components/button'; | ||
|
||
interface Props { | ||
contributorTypes: ABT.ContributorField[]; | ||
index: number; | ||
contributor: ABT.Contributor; | ||
onRemove(e: React.MouseEvent<HTMLButtonElement>): void; | ||
} | ||
|
||
@observer | ||
export default class Contributor extends React.Component<Props> { | ||
static readonly labels = top.ABT.i18n.dialogs.add.contributor; | ||
|
||
@observable isLiteral: boolean; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
this.isLiteral = props.contributor.literal ? true : false; | ||
} | ||
|
||
@action | ||
update = (e: React.FormEvent<HTMLInputElement | HTMLSelectElement>): void => { | ||
const field = e.currentTarget.dataset.field as keyof ABT.Contributor | undefined; | ||
if (!field) { | ||
throw new ReferenceError('"field" property not set on event target'); | ||
} | ||
this.props.contributor[field] = e.currentTarget.value; | ||
}; | ||
|
||
@action | ||
toggleLiteral = (): void => { | ||
this.props.contributor.family = ''; | ||
this.props.contributor.given = ''; | ||
this.props.contributor.literal = ''; | ||
this.isLiteral = !this.isLiteral; | ||
}; | ||
|
||
render(): JSX.Element { | ||
const { contributorTypes, contributor, index, onRemove } = this.props; | ||
return ( | ||
<div> | ||
<select value={contributor.type} onChange={this.update} data-field="type"> | ||
{contributorTypes.map(p => ( | ||
<option | ||
key={p.type} | ||
aria-selected={contributor.type === p.type} | ||
value={p.type} | ||
children={p.label} | ||
/> | ||
))} | ||
</select> | ||
{this.isLiteral && ( | ||
<input | ||
type="text" | ||
placeholder={Contributor.labels.literal} | ||
aria-label={Contributor.labels.literal} | ||
value={contributor.literal} | ||
data-field="literal" | ||
onChange={this.update} | ||
required={true} | ||
/> | ||
)} | ||
{!this.isLiteral && ( | ||
<React.Fragment> | ||
<input | ||
type="text" | ||
placeholder={Contributor.labels.surname} | ||
aria-label={Contributor.labels.surname} | ||
value={contributor.family} | ||
data-field="family" | ||
onChange={this.update} | ||
required={true} | ||
/> | ||
<input | ||
type="text" | ||
placeholder={Contributor.labels.given} | ||
aria-label={Contributor.labels.given} | ||
value={contributor.given} | ||
data-field="given" | ||
onChange={this.update} | ||
required={true} | ||
/> | ||
</React.Fragment> | ||
)} | ||
<Button | ||
flat | ||
icon={this.isLiteral ? 'groups' : 'admin-users'} | ||
label={Contributor.labels.toggleLiteral} | ||
onClick={this.toggleLiteral} | ||
/> | ||
<Button | ||
flat | ||
icon="no-alt" | ||
label={Contributor.labels.remove} | ||
onClick={onRemove} | ||
data-index={index} | ||
/> | ||
<style jsx>{` | ||
div { | ||
display: flex; | ||
padding: 0 5px; | ||
align-items: center; | ||
} | ||
input[type='text'] { | ||
flex: auto; | ||
height: 28px; | ||
line-height: 28px; | ||
font-size: 14px; | ||
} | ||
select, | ||
input { | ||
margin: 0 5px; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { action, IObservableArray } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
|
||
import Button from 'components/button'; | ||
import Contributor from './contributor'; | ||
|
||
interface Props { | ||
citationType: keyof ABT.FieldMappings; | ||
people: IObservableArray<ABT.Contributor>; | ||
} | ||
|
||
@observer | ||
export default class ContributorList extends React.Component<Props> { | ||
static readonly fieldmaps = top.ABT.i18n.fieldmaps; | ||
static readonly labels = top.ABT.i18n.dialogs.add.contributorList; | ||
|
||
@action | ||
add = (): void => { | ||
this.props.people.push({ family: '', given: '', literal: '', type: 'author' }); | ||
}; | ||
|
||
@action | ||
remove = (e: React.MouseEvent<HTMLInputElement>): void => { | ||
const index = parseInt(e.currentTarget.dataset.index!, 10); | ||
this.props.people.remove(this.props.people[index]); | ||
}; | ||
|
||
render(): JSX.Element { | ||
let key = Date.now(); | ||
const contributorTypes = ContributorList.fieldmaps[this.props.citationType].people; | ||
return ( | ||
<div> | ||
<h2 children={ContributorList.labels.contributors} /> | ||
{this.props.people.map((contributor, i) => ( | ||
<Contributor | ||
key={key++} | ||
index={i} | ||
contributorTypes={contributorTypes} | ||
contributor={contributor} | ||
onRemove={this.remove} | ||
/> | ||
))} | ||
<div className="btn-row"> | ||
<Button flat label={ContributorList.labels.add} onClick={this.add} /> | ||
</div> | ||
<style jsx>{` | ||
.btn-row { | ||
display: flex; | ||
justify-content: center; | ||
padding: 5px; | ||
} | ||
h2 { | ||
font-size: 16px !important; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.