From d0c911a7db11fc566e034931fe3f3cce54de1859 Mon Sep 17 00:00:00 2001 From: Huei Tan Date: Mon, 7 Jun 2021 19:59:36 +0200 Subject: [PATCH] T282717 Add target stories for hyperlink, image and text (#119) * Add target stories for hyperlink, image and text * remove empty line * call init() directly instead of mouseover listener * rename stories name to Targets --- .storybook/main.js | 17 +++++++++++-- src/stories/target.stories.js | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/stories/target.stories.js diff --git a/.storybook/main.js b/.storybook/main.js index 6388ddd6..14967730 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -1,6 +1,7 @@ +const webpack = require('webpack') const path = require('path'); -const custom = require('../webpack.config.js')(null, {mode: 'dev'}); +const custom = require('../webpack.config.js')(null, {mode: 'development'}); module.exports = { "stories": [ @@ -11,6 +12,18 @@ module.exports = { "@storybook/addon-essentials" ], webpackFinal: (config) => { - return { ...config, module: { ...config.module, rules: custom.module.rules } }; + return { + ...config, + plugins: [ + ...config.plugins, + new webpack.DefinePlugin( { + APP_VERSION: '"(mock app version)"', + GIT_HASH: '"(mock git hash)"' + } ) ], + module: { + ...config.module, + rules: custom.module.rules + } + }; }, } diff --git a/src/stories/target.stories.js b/src/stories/target.stories.js new file mode 100644 index 00000000..2498e3b4 --- /dev/null +++ b/src/stories/target.stories.js @@ -0,0 +1,45 @@ +import { buildWikipediaUrl } from '../utils' +import { init } from '../index' + +export default { + title: 'Targets', + argTypes: { + lang: { + name: 'Language', + defaultValue: 'en', + control: { + type: 'select', + options: [ 'en', 'fr', 'hi', 'ks', 'he' ] + } + }, + title: { + name: 'Article Title', + defaultValue: 'Cat', + control: 'text' + } + } +} + +export const Hyperlink = ( { lang, title } ) => { + const container = document.createElement( 'div' ) + const template = `${title} (${lang})` + container.innerHTML = template + init( { root: container, detectLinks: true } ) + return container +} + +export const Image = ( { lang, title } ) => { + const container = document.createElement( 'div' ) + const template = `` + container.innerHTML = template + init( { root: container, detectLinks: true } ) + return container +} + +export const Text = ( { lang, title } ) => { + const container = document.createElement( 'div' ) + const template = `${title} (${lang})` + container.innerHTML = template + init( { root: container, lang } ) + return container +}