Skip to content

Commit 58014b2

Browse files
authored
Merge pull request #2899 from chmelevskij/storybook
add storybook setup
2 parents b98e042 + 585cce1 commit 58014b2

File tree

7 files changed

+6691
-115
lines changed

7 files changed

+6691
-115
lines changed

.storybook/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials"
9+
],
10+
"framework": "@storybook/vue",
11+
"staticDirs": [
12+
{ from: "../locales", to: "/locales" },
13+
{ from: "../src/css", to: "/css" },
14+
]
15+
}

.storybook/preview.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Vue from "vue";
2+
import VueI18Next from "@panter/vue-i18next";
3+
import i18next from "i18next";
4+
import i18nextXHRBackend from "i18next-xhr-backend";
5+
6+
/**
7+
* Logic from ../src/js/localization.js
8+
*/
9+
function parseInputFile(data) {
10+
// Remove the $n interpolate of Chrome $1, $2, ... -> {{1}}, {{2}}, ...
11+
const REGEXP_CHROME = /\$([1-9])/g;
12+
const dataChrome = data.replace(REGEXP_CHROME, "{{$1}}");
13+
14+
// Remove the .message of the nesting $t(xxxxx.message) -> $t(xxxxx)
15+
const REGEXP_NESTING = /\$t\(([^\)]*).message\)/g;
16+
const dataNesting = dataChrome.replace(REGEXP_NESTING, "$t($1)");
17+
18+
// Move the .message of the json object to root xxxxx.message -> xxxxx
19+
const jsonData = JSON.parse(dataNesting);
20+
Object.entries(jsonData).forEach(([key, value]) => {
21+
jsonData[key] = value.message;
22+
});
23+
24+
return jsonData;
25+
}
26+
27+
i18next.use(i18nextXHRBackend).init({
28+
lng: "en",
29+
debug: true,
30+
getAsync: false,
31+
ns: ["messages"],
32+
defaultNS: ["messages"],
33+
fallbackLng: {
34+
default: ["en"],
35+
},
36+
backend: {
37+
loadPath: "/locales/{{lng}}/{{ns}}.json",
38+
parse: parseInputFile,
39+
},
40+
});
41+
42+
Vue.use(VueI18Next);
43+
44+
const i18n = new VueI18Next(i18next);
45+
46+
export const decorators = [
47+
(story) => ({
48+
i18n,
49+
components: { story },
50+
template: `
51+
<div style="margin: 1rem;">
52+
<link rel="stylesheet" href="/css/opensans_webfontkit/fonts.css" />
53+
<link rel="stylesheet" href="/css/main.css" />
54+
<story />
55+
</div>
56+
`,
57+
}),
58+
];
59+
60+
export const parameters = {
61+
actions: { argTypesRegex: "^on[A-Z].*" },
62+
controls: {
63+
matchers: {
64+
color: /(background|color)$/i,
65+
date: /Date$/,
66+
},
67+
},
68+
};

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"pretest": "yarn run lint",
1717
"test": "karma start test/karma.conf.js",
1818
"lint": "eslint --ext .js,.vue src gulpfile.js gulp-appdmg.js",
19-
"lint:fix": "eslint --fix src gulpfile.js gulp-appdmg.js"
19+
"lint:fix": "eslint --fix src gulpfile.js gulp-appdmg.js",
20+
"storybook": "start-storybook -p 6006"
2021
},
2122
"window": {
2223
"icon": "images/bf_icon_128.png",
@@ -77,11 +78,17 @@
7778
"vue": "2.6.12"
7879
},
7980
"devDependencies": {
81+
"@babel/core": "^7.17.9",
8082
"@quanle94/innosetup": "^6.0.2",
8183
"@rollup/plugin-alias": "^3.1.1",
8284
"@rollup/plugin-commonjs": "^15.1.0",
8385
"@rollup/plugin-node-resolve": "^9.0.0",
8486
"@rollup/plugin-replace": "^2.3.3",
87+
"@storybook/addon-actions": "^6.4.22",
88+
"@storybook/addon-essentials": "^6.4.22",
89+
"@storybook/addon-links": "^6.4.22",
90+
"@storybook/vue": "^6.4.22",
91+
"babel-loader": "^8.2.4",
8592
"browserify": "^17.0.0",
8693
"chai": "^4.2.0",
8794
"command-exists": "^1.2.8",
@@ -129,6 +136,7 @@
129136
"temp": "^0.9.1",
130137
"through2": "^4.0.2",
131138
"vinyl-source-stream": "^2.0.0",
139+
"vue-loader": "^15.9.8",
132140
"vue-template-compiler": "^2.6.12",
133141
"yarn": "^1.22.17"
134142
},
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import BetaflightLogo from './BetaflightLogo.vue';
2+
3+
// More on default export: https://storybook.js.org/docs/vue/writing-stories/introduction#default-export
4+
export default {
5+
title: 'Logo',
6+
component: BetaflightLogo,
7+
};
8+
9+
// More on component templates: https://storybook.js.org/docs/vue/writing-stories/introduction#using-args
10+
const Template = (_args, { argTypes }) => ({
11+
props: Object.keys(argTypes),
12+
components: { BetaflightLogo },
13+
template: '<betaflight-logo v-bind="$props" />',
14+
});
15+
16+
export const Primary = Template.bind({});
17+
// More on args: https://storybook.js.org/docs/vue/writing-stories/args
18+
Primary.args = {
19+
configuratorVersion: '1.0.0',
20+
};

src/components/betaflight-logo/BetaflightLogo.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default {
4242
.logo {
4343
height: 70px;
4444
width: 240px;
45-
background-image: url(./images/light-wide-2.svg);
45+
background-image: url(../../images/light-wide-2.svg);
4646
background-repeat: no-repeat;
4747
background-position: left center;
4848
background-size: contain;
@@ -70,7 +70,7 @@ export default {
7070
.logo {
7171
height: 24px;
7272
width: 150px;
73-
background-image: url(./images/light-wide-2-compact.svg);
73+
background-image: url(../../images/light-wide-2-compact.svg);
7474
background-position: left center;
7575
order: 2;
7676
margin-top: 0;
@@ -80,7 +80,7 @@ export default {
8080
}
8181
.tab_container .logo {
8282
display: block;
83-
background-image: url(./images/light-wide-2.svg);
83+
background-image: url(../../images/light-wide-2.svg);
8484
background-repeat: no-repeat;
8585
background-position: center 20px;
8686
background-position-x: 12px;

src/components/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ i18next.on('initialized', function() {
4141
},
4242
data: betaflightModel,
4343
});
44-
4544
});
4645

4746

0 commit comments

Comments
 (0)