From 0ea4b53e747a2b82f908192d45948839f5def485 Mon Sep 17 00:00:00 2001 From: Shota Fuji Date: Wed, 11 Dec 2019 07:38:44 +0000 Subject: [PATCH] feat: Add case conversion option --- README.md | 52 +++++++++++--- example/.storybook/config.js | 8 +-- example/stories/issues/122/camel.vue | 14 ++++ example/stories/issues/122/index.stories.js | 80 +++++++++++++++++++++ example/stories/issues/122/kebab.vue | 14 ++++ example/stories/issues/122/mixed.vue | 18 +++++ src/components/Component/index.vue | 29 +++++++- src/components/Wrapper/index.vue | 21 +++++- src/options.ts | 19 ++++- 9 files changed, 233 insertions(+), 22 deletions(-) create mode 100644 example/stories/issues/122/camel.vue create mode 100644 example/stories/issues/122/index.stories.js create mode 100644 example/stories/issues/122/kebab.vue create mode 100644 example/stories/issues/122/mixed.vue diff --git a/README.md b/README.md index 58ece70..a486a0a 100644 --- a/README.md +++ b/README.md @@ -126,17 +126,47 @@ For more details, see [live examples]. ## Options -| Name | Data type | Default value | Description | -| ------------------ | ------------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------- | -| `header` | `boolean` | `true` | Whether to show header or not. | -| `source` | `boolean` | `true` | Whether to show source(usage) or not. | -| `wrapperComponent` | `Component` | [default wrapper](src/components/Wrapper/index.vue) | Override inline docs component. | -| `previewClassName` | `string` | `undefined` | Class name passed down to preview container. | -| `previewStyle` | Style object | `undefined` | Style passed down to preview container. | -| `summary` | `string` | `''` | Summary for the story. Accepts Markdown. | -| `components` | `{ [name: string]: Component }\|null` | `null` | Display info for these components. Same type as component's `components` property. | -| `docsInPanel` | `boolean` | `true` | Whether to show docs in addon panel. | -| `useDocgen` | `boolean` | `true` | Whether to use result of vue-docgen-api. | +| Name | Data type | Default value | Description | +| ------------------ | --------------------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------- | +| `header` | `boolean` | `true` | Whether to show header or not. | +| `source` | `boolean` | `true` | Whether to show source(usage) or not. | +| `wrapperComponent` | `Component` | [default wrapper](src/components/Wrapper/index.vue) | Override inline docs component. | +| `previewClassName` | `string` | `undefined` | Class name passed down to preview container. | +| `previewStyle` | Style object | `undefined` | Style passed down to preview container. | +| `summary` | `string` | `''` | Summary for the story. Accepts Markdown. | +| `components` | `{ [name: string]: Component }\|null` | `null` | Display info for these components. Same type as component's `components` property. | +| `docsInPanel` | `boolean` | `true` | Whether to show docs in addon panel. | +| `useDocgen` | `boolean` | `true` | Whether to use result of vue-docgen-api. | +| `casing` | `"kebab" \| "camel" \| "pascal" \| undefined` | `undefined` | Which case to use. For detailed usage, see below. | + +### Valid `casing` options + +```js +{ + // Don't convert names + casing: undefined +} + +{ + // Show names in kebab-case + casing 'kebab' +} + +{ + // Show prop names in camelCase and + // Show component names in PascalCase + casing: 'camel' // or 'pascal' +} + +{ + // Show prop names in camelCase and + // Show component names in kebab-case + casing: { + props: 'camel', + component: 'kebab' + } +} +``` In addition to addon options, we have a component option. diff --git a/example/.storybook/config.js b/example/.storybook/config.js index c72f5e7..f64b5cc 100644 --- a/example/.storybook/config.js +++ b/example/.storybook/config.js @@ -13,10 +13,4 @@ Vue.use(VueI18n) addDecorator(withInfo) -const req = require.context('../stories', true, /\.stories\.js$/) - -function loadStories() { - req.keys().forEach(req) -} - -configure(loadStories, module) +configure(require.context('../stories', true, /\.stories\.js$/), module) diff --git a/example/stories/issues/122/camel.vue b/example/stories/issues/122/camel.vue new file mode 100644 index 0000000..4d1fbe6 --- /dev/null +++ b/example/stories/issues/122/camel.vue @@ -0,0 +1,14 @@ + + + diff --git a/example/stories/issues/122/index.stories.js b/example/stories/issues/122/index.stories.js new file mode 100644 index 0000000..a0c6c85 --- /dev/null +++ b/example/stories/issues/122/index.stories.js @@ -0,0 +1,80 @@ +import CamelComponent from './camel.vue' +import KebabComponent from './kebab.vue' +import MixedComponent from './mixed.vue' + +export default { + title: 'Issues/#122' +} + +export const camelToKebab = () => { + return { + components: { CamelComponent }, + template: '' + } +} +camelToKebab.story = { + title: 'Convert camelCase to kebab-case', + parameters: { + info: { + casing: 'kebab' + } + } +} + +export const kebabToCamel = () => { + return { + components: { KebabComponent }, + template: '' + } +} +kebabToCamel.story = { + title: 'Convert kebab-case to camelCase', + parameters: { + info: { + casing: 'camel' + } + } +} + +export const mixedToKebab = () => { + return { + components: { MixedComponent }, + template: '' + } +} +mixedToKebab.story = { + title: 'Convert to kebab-case (mixed)', + parameters: { + info: { + casing: 'kebab' + } + } +} + +export const mixedToCamel = () => { + return { + components: { MixedComponent }, + template: '' + } +} +mixedToCamel.story = { + title: 'Convert to camelCase (mixed)', + parameters: { + info: { + casing: 'camel' + } + } +} + +export const preserve = () => { + return { + components: { MixedComponent }, + template: '' + } +} +preserve.story = { + title: 'Preserve casing when undefined', + parameters: { + info: {} + } +} diff --git a/example/stories/issues/122/kebab.vue b/example/stories/issues/122/kebab.vue new file mode 100644 index 0000000..5193fc9 --- /dev/null +++ b/example/stories/issues/122/kebab.vue @@ -0,0 +1,14 @@ + + + diff --git a/example/stories/issues/122/mixed.vue b/example/stories/issues/122/mixed.vue new file mode 100644 index 0000000..627c69d --- /dev/null +++ b/example/stories/issues/122/mixed.vue @@ -0,0 +1,18 @@ + + + diff --git a/src/components/Component/index.vue b/src/components/Component/index.vue index 34f6c78..1da7247 100644 --- a/src/components/Component/index.vue +++ b/src/components/Component/index.vue @@ -1,4 +1,5 @@ @@ -51,7 +65,12 @@ export default { :lang="info.jsxStory ? 'jsx' : 'html'" /> - + diff --git a/src/options.ts b/src/options.ts index 9864d70..6b3f3a9 100644 --- a/src/options.ts +++ b/src/options.ts @@ -9,9 +9,19 @@ export const defaultOptions: InfoAddonOptions = { components: null, wrapperComponent: DefaultWrapper, docsInPanel: true, - useDocgen: true + useDocgen: true, + casing: undefined } +type Casing = + | undefined + | 'camel' + | 'camelCase' + | 'kebab' + | 'kebab-case' + | 'pascal' + | 'PascalCase' + /** * Addon options */ @@ -53,4 +63,11 @@ export interface InfoAddonOptions { * Whether to use component infomation generated by vue-docgen-api */ useDocgen: boolean + + casing: + | Casing + | { + props: Casing + component: Casing + } }