├── .gitignore
├── components
├── kickoff-react
│ ├── Actions.js
│ ├── Button.js
│ ├── Checkbox.js
│ ├── Column.js
│ ├── Control.js
│ ├── Fieldset.js
│ ├── Form.js
│ ├── Grid.js
│ ├── Input.js
│ ├── Label.js
│ ├── Legend.js
│ ├── RadioButton.js
│ └── Textarea.js
└── pre.js
├── layouts
└── page.js
├── now.json
├── package.json
├── pages
└── index.js
├── readme.md
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .next
3 | *.sublime-*
4 | .vercel
--------------------------------------------------------------------------------
/components/kickoff-react/Actions.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Actions = ({ children }) => (
4 |
{children}
5 | )
6 |
--------------------------------------------------------------------------------
/components/kickoff-react/Button.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Button = ({ primary, type, value }) => {
4 | let className = 'btn'
5 | if (primary) {
6 | className += ' btn--primary'
7 | }
8 | return
9 | }
10 |
--------------------------------------------------------------------------------
/components/kickoff-react/Checkbox.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 |
3 | export class Checkbox extends Component {
4 | constructor(props) {
5 | super(props)
6 | this.state = {
7 | checked: props.checked || false,
8 | }
9 |
10 | this.onChange = this.onChange.bind(this)
11 | }
12 |
13 | onChange() {
14 | const checked = !this.state.checked
15 | this.setState({ checked })
16 | }
17 |
18 | render() {
19 | let className = 'control-indicator control-indicator--checkbox'
20 | if (this.props.tickbox) {
21 | className = 'control-indicator control-indicator--tickbox'
22 | }
23 | return (
24 |
35 | )
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/components/kickoff-react/Column.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Column = ({ centered, children, mid, span }) => {
4 | let className = 'g-col'
5 | if (span) {
6 | className += ' g-span' + span
7 | }
8 | if (mid) {
9 | className += ' g-span' + mid + '--mid'
10 | }
11 | if (centered) {
12 | className += ' g-col--centered'
13 | }
14 | return {children}
15 | }
16 |
--------------------------------------------------------------------------------
/components/kickoff-react/Control.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Control = ({ children, error, success, warning }) => {
4 | let className = 'form-controlGroup'
5 | if (success) {
6 | className += ' has-success'
7 | } else if (error) {
8 | className += ' has-error'
9 | } else if (warning) {
10 | className += ' has-warning'
11 | }
12 | return {children}
13 | }
14 |
--------------------------------------------------------------------------------
/components/kickoff-react/Fieldset.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Fieldset = ({ children }) => (
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/components/kickoff-react/Form.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Form = ({ children, horizontal }) => {
4 | let className = 'form'
5 | if (horizontal) {
6 | className += ' form--horizontal'
7 | }
8 | return
9 | }
10 |
--------------------------------------------------------------------------------
/components/kickoff-react/Grid.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Grid = ({ children, gutter, scaled, stack }) => {
4 | let className = 'g'
5 | if (gutter && scaled) {
6 | className += ' g--gutter--scaled'
7 | } else if (gutter) {
8 | className += ' g--gutter'
9 | }
10 | if (typeof stack === 'string') {
11 | className += ' g--stack--' + stack
12 | } else if (stack) {
13 | className += ' g--stack'
14 | }
15 | return {children}
16 | }
17 |
--------------------------------------------------------------------------------
/components/kickoff-react/Input.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Input = (props) => (
4 |
5 |
6 |
7 | )
8 |
--------------------------------------------------------------------------------
/components/kickoff-react/Label.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Label = ({ children }) => (
4 | {children}
5 | )
6 |
--------------------------------------------------------------------------------
/components/kickoff-react/Legend.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Legend = ({ children }) => (
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/components/kickoff-react/RadioButton.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 |
3 | export class RadioButton extends Component {
4 | render() {
5 | return (
6 |
11 | )
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/components/kickoff-react/Textarea.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Textarea = (props) => (
4 |
5 |
6 |
7 | )
8 |
--------------------------------------------------------------------------------
/components/pre.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export const Pre = (props) => {
4 | const editors = {
5 | sublime: {
6 | snippet: `
7 |
8 | ${props.description}
9 | ${props.tabtrigger}
10 | ${props.scope}
11 | `,
12 | note: `Create a new *.sublime-snippet file and save the contents above into it.`,
13 | docslink:
14 | 'http://docs.sublimetext.info/en/latest/extensibility/snippets.html',
15 | },
16 |
17 | atom: {
18 | snippet: `'.${props.scope}':
19 | '${props.description}':
20 | 'prefix': '${props.tabtrigger}'
21 | 'body': """
22 | ${props.snippet.replace(/\\/gm, '\\\\\\\\')}
23 | """`,
24 | note: `Paste the above code into your snippets.cson.`,
25 | docslink: 'http://flight-manual.atom.io/using-atom/sections/snippets/',
26 | },
27 |
28 | vscode: {
29 | snippet: `"snippet-${props.tabtrigger}": {
30 | "prefix": "${props.tabtrigger}",
31 | "body": "${props.snippet
32 | .replace(/\n/gm, '\\n')
33 | .replace(/\t/gm, '\\t')
34 | .replace(/\r/gm, '\\r')}",
35 | "description": "${props.description}"
36 | }`,
37 | note: `Go to 'Preferences' > 'User snippets' and select the correct type, then paste in the above code.`,
38 | docslink: 'https://code.visualstudio.com/docs/editor/userdefinedsnippets',
39 | },
40 | }
41 |
42 | const editor = props.editor.toLowerCase().replace(' ', '')
43 |
44 | return (
45 |
46 |
{props.editor}
47 |
48 |
49 | {editors[editor].snippet.replace(/\$(?!{|[0-9])/gim, '\\$')}
50 |
51 |
52 |
57 |
75 |
76 | )
77 | }
78 |
--------------------------------------------------------------------------------
/layouts/page.js:
--------------------------------------------------------------------------------
1 | import Head from 'next/head'
2 | const colors = {
3 | accent: '#DA37CF',
4 | copy: '#444',
5 | bg: '#fff',
6 | }
7 |
8 | export default ({ children }) => (
9 |
10 |
11 | Sublime Text, Atom & VS Code snippet generator
12 |
13 |
14 |
18 |
19 |
20 | {children}
21 |
22 |
37 |
38 |
92 |
93 | )
94 |
--------------------------------------------------------------------------------
/now.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "scope": "zander",
4 | "alias": "snippets.zander.wtf"
5 | }
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "snippet-generator",
3 | "version": "1.0.0",
4 | "description": "Sublime Text, Atom & VS Code snippet generator",
5 | "main": "pages/index.js",
6 | "author": "Zander Martineau",
7 | "license": "MIT",
8 | "dependencies": {
9 | "next": "^9.4.4",
10 | "react": "^16.13.1",
11 | "react-dom": "^16.13.1"
12 | },
13 | "scripts": {
14 | "start": "next start",
15 | "build": "next build",
16 | "dev": "next"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/pages/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Pre } from '../components/pre'
3 | import { Grid } from '../components/kickoff-react/Grid'
4 | import { Column } from '../components/kickoff-react/Column'
5 | import { Control } from '../components/kickoff-react/Control'
6 | import { Input } from '../components/kickoff-react/Input'
7 | import { Textarea } from '../components/kickoff-react/Textarea'
8 |
9 | // Layouts
10 | import Page from '../layouts/page'
11 |
12 | export default class Index extends Component {
13 | constructor(props) {
14 | super(props)
15 | this.state = {
16 | snippet: '',
17 | description: '',
18 | tabtrigger: '',
19 | scope: '',
20 | editorSublime: true,
21 | editorVSCode: false,
22 | editorAtom: false,
23 | }
24 |
25 | this.handleSnippetChange = this.handleSnippetChange.bind(this)
26 | this.handleDescriptionChange = this.handleDescriptionChange.bind(this)
27 | this.handleTabTriggerChange = this.handleTabTriggerChange.bind(this)
28 | this.handleScopeChange = this.handleScopeChange.bind(this)
29 | this.handleExample = this.handleExample.bind(this)
30 | this.handleScopeExample = this.handleScopeExample.bind(this)
31 | this.handleClear = this.handleClear.bind(this)
32 | this.handleKeyDown = this.handleKeyDown.bind(this)
33 | }
34 |
35 | handleSnippetChange(event) {
36 | this.setState({
37 | snippet: event.target.value,
38 | })
39 | }
40 |
41 | handleDescriptionChange(event) {
42 | this.setState({
43 | description: event.target.value,
44 | })
45 | }
46 |
47 | handleTabTriggerChange(event) {
48 | this.setState({
49 | tabtrigger: event.target.value,
50 | })
51 | }
52 |
53 | handleScopeChange(event) {
54 | this.setState({
55 | scope: event.target.value,
56 | })
57 | }
58 |
59 | handleScopeExample(event) {
60 | this.setState({
61 | scope: event.target.textContent,
62 | })
63 | }
64 |
65 | handleKeyDown(event) {
66 | if (event.keyCode === 9) {
67 | event.preventDefault()
68 | const snippet = this.state.snippet
69 | const selectionStart = event.target.selectionStart
70 | const snippetStart = snippet.slice(0, selectionStart)
71 | const snippetEnd = snippet.slice(selectionStart)
72 | console.log(event.target.selectionEnd)
73 | this.setState({
74 | snippet: `${snippetStart}\t${snippetEnd}`,
75 | })
76 | // event.target.selectionStart = event.target.selectionEnd = selectionStart + 1;
77 | }
78 | }
79 |
80 | handleClear(event) {
81 | event.preventDefault()
82 | this.setState({
83 | snippet: '',
84 | description: '',
85 | tabtrigger: '',
86 | scope: '',
87 | })
88 | }
89 |
90 | handleExample(event) {
91 | event.preventDefault()
92 | this.setState({
93 | snippet: `const \${1:fn} = ($2) => {
94 | $3
95 | }`,
96 | description: 'Creates an anonymous function in ES6 syntax',
97 | tabtrigger: 'anfn',
98 | scope: 'source.js',
99 | })
100 | }
101 |
102 | render() {
103 | const preProps = {
104 | snippet: this.state.snippet,
105 | description: this.state.description,
106 | tabtrigger: this.state.tabtrigger,
107 | scope: this.state.scope,
108 | }
109 |
110 | return (
111 |
112 |
113 |
Snippet Generator
114 |
115 | Sublime Text, Atom & VS Code snippet generator
116 |
117 |
118 | Convert snippets across your text editors
119 |
120 |
121 |
122 |
123 |
124 |
130 |
131 |
144 |
145 |
146 |
147 |
148 |
149 |
154 |
155 |
156 |
164 |
165 |
166 |
174 |
175 | e.g. source.js
,{' '}
176 | source.css
or{' '}
177 | text.html
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
210 |
211 | )
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Snippets
2 |
3 | > Sublime Text, Atom & VS Code snippet generator
4 |
5 | Go to https://snippets.zander.wtf
6 |
7 | ---
8 |
9 | ## License
10 |
11 | [MIT](https://choosealicense.com/licenses/mit/) © [Zander Martineau](https://zander.wtf)
12 |
13 | > Made by [Zander ⚡](https://github.com/mrmartineau/)
14 |
--------------------------------------------------------------------------------