-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 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,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 = `<a href="${buildWikipediaUrl( lang, title, true, false )}">${title} (${lang})</a>` | ||
container.innerHTML = template | ||
init( { root: container, detectLinks: true } ) | ||
return container | ||
} | ||
|
||
export const Image = ( { lang, title } ) => { | ||
const container = document.createElement( 'div' ) | ||
const template = `<a href="${buildWikipediaUrl( lang, title, true, false )}"><img src="https://upload.wikimedia.org/wikipedia/commons/3/3d/Wikipedia-logo-v2.png"></a>` | ||
container.innerHTML = template | ||
init( { root: container, detectLinks: true } ) | ||
return container | ||
} | ||
|
||
export const Text = ( { lang, title } ) => { | ||
const container = document.createElement( 'div' ) | ||
const template = `<span class="wmf-wp-with-preview" data-wikipedia-preview data-wp-title="${title}">${title} (${lang})</span>` | ||
container.innerHTML = template | ||
init( { root: container, lang } ) | ||
return container | ||
} |