forked from pkp/ui-library
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#3594 Add checkbox/radio input field component
- Loading branch information
Showing
17 changed files
with
174 additions
and
42 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,108 @@ | ||
<template> | ||
<fieldset class="pkpFormField pkpFormField--options" :class="classes"> | ||
<legend> | ||
{{ maybeLocalize(label, localeKey) }} | ||
<span v-if="isRequired" class="pkpFormFieldLabel__required"> | ||
* | ||
<span class="-screenReader">{{ i18n.required }}</span> | ||
</span> | ||
<tooltip v-if="tooltip" :id="describedByTooltipId" :tooltip="tooltip" :label="this.__('tooltip', {label: maybeLocalize(this.label, localeKey)})" /> | ||
<help-button v-if="helpTopic" :id="describedByHelpId" :topic="helpTopic" :label="i18n.help" /> | ||
</legend> | ||
<div v-if="description" | ||
class="pkpFormField__description" | ||
v-html="maybeLocalize(description, localeKey)" | ||
:id="describedByDescriptionId" | ||
/> | ||
<div class="pkpFormField__control"> | ||
<label v-for="option in localizedOptions"> | ||
<input | ||
class="pkpFormField--options__input" | ||
v-model="selectedValue" | ||
:value="option.value" | ||
:type="type" | ||
:aria-describedby="describedByIds" | ||
:disabled="option.disabled" | ||
/> | ||
{{ option.label }} | ||
</label> | ||
</div> | ||
</fieldset> | ||
</template> | ||
|
||
<script> | ||
import FieldBase from './FieldBase'; | ||
export default { | ||
name: 'FieldOptions', | ||
extends: FieldBase, | ||
props: { | ||
type: { | ||
validator: function (value) { | ||
return ['checkbox', 'radio'].includes(value); | ||
}, | ||
default: 'checkbox', | ||
}, | ||
options: { | ||
type: Array, | ||
required: true, | ||
}, | ||
value: { | ||
type: [Array, String], | ||
required: true, | ||
}, | ||
}, | ||
data: function () { | ||
return { | ||
/** | ||
* This replaces the computed `currentValue` property in FieldBase. We | ||
* use a custom watcher for checkboxes so that all change events are | ||
* recorded. The computed property's setter function is not called when | ||
* an option is deselected. See: https://github.com/vuejs/vuex/issues/249 | ||
*/ | ||
selectedValue: this.isMultilingual ? this.value[this.localeKey] : this.value, | ||
}; | ||
}, | ||
computed: { | ||
/** | ||
* Get classes for the wrapper element | ||
* | ||
* @return array | ||
*/ | ||
classes: function () { | ||
return ['pkpFormField--' + this.type]; | ||
}, | ||
/** | ||
* Get localized set of options | ||
* | ||
* @return array | ||
*/ | ||
localizedOptions: function () { | ||
return this.isMultingual ? this.options[this.localeKey] : this.options; | ||
}, | ||
}, | ||
mounted: function () { | ||
/** | ||
* Whenever the current value changes, emit an event to update the value of | ||
* this field in the form component. | ||
*/ | ||
this.$watch('selectedValue', function (newVal, oldVal) { | ||
if (newVal === oldVal) { | ||
return; | ||
} | ||
this.$emit('change', { | ||
name: this.name, | ||
value: newVal, | ||
localeKey: this.localeKey, | ||
}); | ||
}); | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="less"> | ||
@import '../../../styles/_import'; | ||
</style> |
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
7 changes: 0 additions & 7 deletions
7
src/docs/examples/Form/implementations/helpers/field-checkbox-user-locales.js
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/docs/examples/Form/implementations/helpers/field-options-user-locales.js
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,22 @@ | ||
export default { | ||
name: 'user-locales', | ||
component: 'field-options', | ||
label: 'Working Languages', | ||
description: 'Disable language options that you can not use.', | ||
value: [], | ||
options: [ | ||
{ | ||
value: 'en_US', | ||
label: 'English', | ||
}, | ||
{ | ||
value: 'fr_CA', | ||
label: 'French (Canadian)', | ||
}, | ||
{ | ||
value: 'ar_AR', | ||
label: 'عربى', | ||
}, | ||
], | ||
groupId: 'preferences', | ||
}; |
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 |
---|---|---|
|
@@ -11,4 +11,8 @@ export default { | |
} | ||
groupId: 'contact', | ||
isMultilingual: true, | ||
value: { | ||
en_US: '', | ||
fr_CA: '', | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -173,6 +173,7 @@ export default { | |
label: '...', | ||
}, | ||
], | ||
value: '', | ||
groupId: 'contact', | ||
isRequired: true, | ||
}; |
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 |
---|---|---|
|
@@ -8,4 +8,8 @@ export default { | |
}, | ||
groupId: 'identity', | ||
isMultilingual: true, | ||
value: { | ||
en_US: '', | ||
fr_CA: '', | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ export default { | |
label: 'Email', | ||
groupId: 'identity', | ||
isRequired: true, | ||
value: '', | ||
}; |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ export default { | |
label: 'Family Name', | ||
groupId: 'identity', | ||
isRequired: true, | ||
value: '', | ||
}; |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ export default { | |
label: 'Given Name', | ||
groupId: 'identity', | ||
isRequired: true, | ||
value: '', | ||
}; |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ export default { | |
inputType: 'tel', | ||
label: 'Phone', | ||
groupId: 'contact', | ||
value: '', | ||
}; |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ export default { | |
label: 'Mailing Address', | ||
groupId: 'contact', | ||
size: 'small', | ||
value: '', | ||
}; |
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