-
Notifications
You must be signed in to change notification settings - Fork 48
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#9527 Add FieldControlledVocab to storybook
- Loading branch information
1 parent
a062b70
commit 4015e95
Showing
4 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Primary, Controls, Stories, Meta, ArgTypes} from '@storybook/blocks'; | ||
|
||
import * as FieldControlledVocabStories from './FieldControlledVocab.stories.js'; | ||
|
||
<Meta of={FieldControlledVocabStories} /> | ||
|
||
# FieldControlledVocab | ||
|
||
## Usage | ||
|
||
This is an implementation of [FieldBaseAutosuggest](#/component/Form/fields/FieldBaseAutosuggest). Used for example for keywords, where it fetches list of keywords from the api, but allow to add additional keywords as well. | ||
|
||
<Primary /> | ||
<Controls /> |
80 changes: 80 additions & 0 deletions
80
src/components/Form/fields/FieldControlledVocab.stories.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,80 @@ | ||
import {http, HttpResponse} from 'msw'; | ||
import FieldControlledVocab from './FieldControlledVocab.vue'; | ||
import FieldBaseMock from '../mocks/field-base'; | ||
import FieldBaseAutosuggest from '../mocks/field-autosuggest'; | ||
|
||
import KeywordsMock from '@/mocks/keywords.json'; | ||
|
||
export default { | ||
title: 'Forms/FieldControlledVocab', | ||
component: FieldControlledVocab, | ||
render: (args) => ({ | ||
components: {FieldControlledVocab}, | ||
setup() { | ||
function change(name, prop, newValue, localeKey) { | ||
if (localeKey) { | ||
args[prop][localeKey] = newValue; | ||
} else { | ||
args[prop] = newValue; | ||
} | ||
} | ||
|
||
return {args, change}; | ||
}, | ||
template: ` | ||
<FieldControlledVocab v-bind="args" @change="change" /> | ||
`, | ||
}), | ||
}; | ||
|
||
export const Base = { | ||
args: { | ||
...FieldBaseMock, | ||
...FieldBaseAutosuggest, | ||
label: 'Keywords', | ||
/*selected: [ | ||
{value: 'keyword1', label: 'keyword1'}, | ||
{value: 'keyword2', label: 'keyword2'}, | ||
], | ||
//value: ['keyword1', 'keyword2'], | ||
value: ['keyword1', 'keyword2'],*/ | ||
|
||
// multi | ||
value: {en: ['keyword1', 'keyword2']}, | ||
selected: { | ||
en: [ | ||
{value: 'keyword1', label: 'keyword1'}, | ||
{value: 'keyword2', label: 'keyword2'}, | ||
], | ||
}, | ||
isMultilingual: true, | ||
localeKey: 'en', | ||
|
||
apiUrl: | ||
'https://mock/index.php/publicknowledge/api/v1/vocabs?vocab=submissionKeyword&locale=en', | ||
/*selected: [ | ||
{ | ||
value: 1, | ||
label: 'Articles', | ||
}, | ||
],*/ | ||
}, | ||
parameters: { | ||
docs: { | ||
story: { | ||
height: '300px', | ||
}, | ||
}, | ||
msw: { | ||
handlers: [ | ||
http.get( | ||
'https://mock/index.php/publicknowledge/api/v1/vocabs?vocab=submissionKeyword&locale=en', | ||
async () => { | ||
return HttpResponse.json(KeywordsMock); | ||
}, | ||
), | ||
], | ||
}, | ||
}, | ||
}; |
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,39 @@ | ||
[ | ||
"21st Century", | ||
"Alberta", | ||
"cattle", | ||
"citizenship", | ||
"Common pool resource", | ||
"common property", | ||
"Computer Skills", | ||
"Culture", | ||
"Development", | ||
"Diversity", | ||
"education", | ||
"Egalitarianism", | ||
"employees", | ||
"engineering education", | ||
"food security", | ||
"Gender", | ||
"Goverance", | ||
"Integrating Technology", | ||
"intellectual developments", | ||
"Language", | ||
"Multi-Level Institutions", | ||
"Multiethnic", | ||
"Multilingual", | ||
"National", | ||
"Participatory Pedagogy", | ||
"pigs", | ||
"Professional Development", | ||
"Provincial", | ||
"Self-Organization", | ||
"service learning", | ||
"Social Transformation", | ||
"survey", | ||
"Survey", | ||
"sustainability", | ||
"Test keyword 1", | ||
"Test keyword 2", | ||
"water" | ||
] |