Skip to content

Commit 48fe048

Browse files
authored
chore: add VS Code code snippets for new components (#5063)
closes #370 Add VSCode emmet snippets that can be used to easily generate initial boilerplate code for new onyx components. They will atuomatically detect the filename for correct snippet generation. Just start typing one of the commands below in a new file and Press Enter/Tab to autofill the code snippet. - `onyx-component` for Vue components - `onyx-component-props` for `types.ts` file - `onyx-compoennt-storybook` for `.stories.ts` file - `onyx-component-playwright` for `.ct.tsx` file (Generated with the help of Gemini :D) ## Checklist - [x] The added / edited code has been documented with [JSDoc](https://jsdoc.app/about-getting-started) - [x] I have performed a self review of my code ("Files changed" tab in the pull request)
1 parent 21b6ad1 commit 48fe048

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vite.*.timestamp*
2424
# Editor directories and files
2525
.vscode/*
2626
!.vscode/extensions.json
27+
!.vscode/*.code-snippets
2728
.idea
2829
*.suo
2930
*.ntvs*

.vscode/onyx.code-snippets

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"New onyx component": {
3+
"prefix": "onyx-component",
4+
"description": "Generates a boilerplate onyx Vue Component based on the filename.",
5+
"isFileTemplate": true,
6+
"scope": "vue",
7+
"body": [
8+
"<script lang=\"ts\" setup>",
9+
"import { useDensity } from \"../../composables/density.js\";",
10+
"import type { ${TM_FILENAME_BASE}Props } from \"./types.js\";",
11+
"",
12+
"const props = defineProps<${TM_FILENAME_BASE}Props>();",
13+
"",
14+
"const { densityClass } = useDensity(props);",
15+
"</script>",
16+
"",
17+
"<template>",
18+
" <div :class=\"['onyx-component', '${TM_FILENAME_BASE/^([A-Z])|([a-z])([A-Z])/${1:/downcase}$2${3:+-}${3:/downcase}/g}', densityClass]\">",
19+
" ${1:<!-- add component content here... -->}",
20+
" </div>",
21+
"</template>",
22+
"",
23+
"<style lang=\"scss\">",
24+
"@use \"../../styles/mixins/layers.scss\";",
25+
"",
26+
".${TM_FILENAME_BASE/^([A-Z])|([a-z])([A-Z])/${1:/downcase}$2${3:+-}${3:/downcase}/g} {",
27+
" @include layers.component() {",
28+
" // add component styles here...",
29+
" }",
30+
"}",
31+
"</style>",
32+
"",
33+
],
34+
},
35+
"New onyx component properties": {
36+
"prefix": "onyx-component-props",
37+
"description": "Generates the property type definition for a new onyx component based on the parent folder name.",
38+
"include": ["types.ts"],
39+
"scope": "typescript",
40+
"body": [
41+
"import type { DensityProp } from \"../../composables/density.js\";",
42+
"",
43+
"export type ${TM_DIRECTORY/.*[\\\\\\/](.*)$/$1/}Props = DensityProp & {",
44+
" $1",
45+
"};",
46+
"",
47+
],
48+
},
49+
"New onyx Storybook file": {
50+
"prefix": "onyx-component-storybook",
51+
"description": "Generates a boilerplate onyx Storybook file based on the filename.",
52+
"isFileTemplate": true,
53+
"scope": "typescript",
54+
"include": ["*.stories.ts"],
55+
"body": [
56+
"import type { Meta, StoryObj } from \"@storybook/vue3-vite\";",
57+
"import ${TM_FILENAME_BASE/\\.stories$//} from \"./${TM_FILENAME_BASE/\\.stories$//}.vue\";",
58+
"",
59+
"const meta: Meta<typeof ${TM_FILENAME_BASE/\\.stories$//}> = {",
60+
" title: \"${1:Support}/${TM_FILENAME_BASE/^Onyx(.*)\\.stories$/$1/}\",",
61+
" component: ${TM_FILENAME_BASE/\\.stories$//},",
62+
"};",
63+
"",
64+
"export default meta;",
65+
"type Story = StoryObj<typeof ${TM_FILENAME_BASE/\\.stories$//}>;",
66+
"",
67+
"export const Default = {",
68+
" args: {",
69+
" ${2:// properties here...}",
70+
" },",
71+
"} satisfies Story;",
72+
"",
73+
],
74+
},
75+
"New onyx Playwright test": {
76+
"prefix": "onyx-component-playwright",
77+
"description": "Generates a boilerplate onyx Playwright screenshot test file based on the filename.",
78+
"scope": "typescriptreact",
79+
"include": ["*.ct.tsx"],
80+
"body": [
81+
"import { useFocusStateHooks } from \"@sit-onyx/playwright-utils\";",
82+
"import { DENSITIES } from \"../../composables/density.js\";",
83+
"import { test } from \"../../playwright/a11y.js\";",
84+
"import { executeMatrixScreenshotTest } from \"../../playwright/screenshots.js\";",
85+
"import ${TM_FILENAME_BASE/\\.ct$//} from \"./${TM_FILENAME_BASE/\\.ct$//}.vue\";",
86+
"",
87+
"test.describe(\"Screenshot tests\", () => {",
88+
" executeMatrixScreenshotTest({",
89+
" name: \"${TM_FILENAME_BASE/\\.ct$//}\",",
90+
" columns: DENSITIES,",
91+
" rows: [\"default\", \"hover\", \"focus-visible\", \"active\"],",
92+
" component: (column) => <${TM_FILENAME_BASE/\\.ct$//} density={column} />,",
93+
" hooks: {",
94+
" beforeEach: async (component, page, column, row) => {",
95+
" await useFocusStateHooks({ component, page, state: row });",
96+
" },",
97+
" },",
98+
" });",
99+
"});",
100+
"",
101+
],
102+
},
103+
}

0 commit comments

Comments
 (0)