├── .editorconfig
├── .eslintrc
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .vscode
├── Front Matter.code-snippets
├── launch.json
└── settings.json
├── .vscodeignore
├── README.md
├── assets
└── icon.png
├── package-lock.json
├── package.json
├── snippet-data
├── api
│ ├── block-variations.snip
│ ├── dom-ready.snip
│ ├── format-api.snip
│ ├── plugin.snip
│ └── register-command.snip
├── block-editor
│ ├── inspector-controls.snip
│ ├── rich-text-content.snip
│ └── rich-text.snip
├── blocks
│ ├── get-categories.snip
│ ├── set-categories.snip
│ └── set-default-block-name.snip
├── components
│ ├── alignment-matrix-control.snip
│ ├── angle-picker-control.snip
│ ├── animate.snip
│ ├── autocomplete.snip
│ ├── base-control.snip
│ ├── button-group.snip
│ ├── button.snip
│ ├── checkbox-control.snip
│ ├── color-indicator.snip
│ ├── color-palette.snip
│ ├── color-picker.snip
│ ├── combobox-control.snip
│ ├── custom-select-controls.snip
│ ├── dashicon.snip
│ ├── date-time-picker.snip
│ ├── disabled.snip
│ ├── draggable.snip
│ ├── dropdown-menu.snip
│ ├── dropdown.snip
│ ├── dropzone.snip
│ ├── duotone-picker-swatch.snip
│ ├── external-link.snip
│ ├── focal-point-picker.snip
│ ├── font-size-picker.snip
│ ├── form-file-upload.snip
│ ├── form-toggle.snip
│ ├── form-token-field.snip
│ ├── guide.snip
│ └── panel-body.snip
├── core-data
│ └── get-current-user.snip
├── data
│ └── get-embed-preview.snip
├── js
│ └── requestAnimationFrame.snip
├── json
│ ├── block.snip
│ └── theme.snip
├── notices
│ ├── create-error-notice.snip
│ ├── create-info-notice.snip
│ ├── create-notice.snip
│ ├── create-success-notice.snip
│ ├── create-warning-notice.snip
│ ├── get-notices.snip
│ └── remove-notice.snip
├── php
│ ├── admin-screen.snip
│ ├── debug.snip
│ ├── enqueue-asset-plugin.snip
│ ├── enqueue-asset-theme.snip
│ └── view-script-enqueue.snip
├── structure
│ ├── block-edit.snip
│ ├── block-save.snip
│ └── get-data.snip
└── webpack
│ └── custom-entry-points.snip
├── snippets
├── api.json
├── block-editor.json
├── blocks.json
├── components.json
├── core-data.json
├── data.json
├── js.json
├── json.json
├── notices.json
├── php.json
├── structure.json
└── webpack.json
└── src
├── constants.js
├── generate-readme.js
├── generate-snippets.js
└── lint-snippet-data.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # This file is for unifying the coding style for different editors and IDEs
2 | # editorconfig.org
3 |
4 | # WordPress Coding Standards
5 | # https://make.wordpress.org/core/handbook/coding-standards/
6 |
7 | root = true
8 |
9 | [*]
10 | charset = utf-8
11 | end_of_line = lf
12 | insert_final_newline = true
13 | trim_trailing_whitespace = true
14 | indent_style = tab
15 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
3 | }
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: CI
4 |
5 | # Controls when the workflow will run
6 | on:
7 | # Triggers the workflow on push or pull request events but only for the trunk branch
8 | push:
9 | branches: [ trunk ]
10 | pull_request:
11 | branches: [ trunk ]
12 |
13 | # Allows you to run this workflow manually from the Actions tab
14 | workflow_dispatch:
15 |
16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
17 | jobs:
18 | # This workflow contains a single job called "build"
19 | Linting:
20 | # The type of runner that the job will run on
21 | runs-on: ubuntu-latest
22 |
23 | # Steps represent a sequence of tasks that will be executed as part of the job
24 | steps:
25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26 | - uses: actions/checkout@v2
27 | - uses: actions/setup-node@v1
28 | with:
29 | node-version: 14
30 |
31 |
32 | # Install
33 | - name: NPM install
34 | run: npm ci
35 |
36 | # Runs a set of commands using the runners shell
37 | - name: Lint JS and snippet data
38 | run: npm run lint
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | test/*
4 | *.vsix
5 |
--------------------------------------------------------------------------------
/.vscode/Front Matter.code-snippets:
--------------------------------------------------------------------------------
1 | {
2 | "Add new snippet": {
3 | "prefix": "snip",
4 | "body": [
5 | "---",
6 | "title: ${1:component}",
7 | "prefix: wp.${2:package}|${2:package}|${1:component}",
8 | "description: ${3:Insert a ${1:component}}",
9 | "---",
10 | "",
11 | "\\$LINE_COMMENT @see ${4:reference-link}",
12 | "",
13 | "${5:snippet}"
14 | ],
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "Run Extension",
6 | "type": "extensionHost",
7 | "request": "launch",
8 | "runtimeExecutable": "${execPath}",
9 | "args": [
10 | "--extensionDevelopmentPath=${workspaceFolder}"
11 | ]
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[css][scss][javascript][json][markdown][yaml][json]": {
3 | "editor.defaultFormatter": "esbenp.prettier-vscode",
4 | "editor.formatOnSave": true
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/.vscodeignore:
--------------------------------------------------------------------------------
1 | .vscode/**
2 | .gitignore
3 | snippet-data/**
4 | src/**
5 | .eslintrc
6 | .editorconfig
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Modern WordPress Development Snippets
2 |
3 | VSCode snippets for modern WordPress development and [Gutenberg](https://wordpress.org/gutenberg/). This is by no means an exhaustive list. It's mostly the items I use during my [live streams](https://www.twitch.tv/ryanwelchercodes) and random projects
4 |
5 | ## Props
6 |
7 | This project was heavily inspired by the [wordpress-components-snippets](https://github.com/ItsJonQ/wordpress-components-snippets) extension and steals the same approach to managing and building the snippets. Thanks to [Q](https://github.com/ItsJonQ/) for the groundwork!
8 |
9 | ## Installation
10 |
11 | 1. Clone the repo `git clone git@github.com:ryanwelcher/gutenberg-snippets.git`
12 | 2. Install dependencies `npm install`
13 | 3. Generate the snippets `npm run generate`
14 | 4. Package the extension `npm run package`
15 | 5. Install the package `npm run load` **You need to have the `code` command line tool installed** [See here for instructions](https://code.visualstudio.com/docs/setup/setup-overview)
16 | 6. Reload VSCode.
17 |
18 | Note that components that are marked as deprecated or experimental are not included in the snippets.
19 |
20 |
21 |
22 | ## Snippets
23 | ### api
24 | | Name | Snippet(s) | Description |
25 | | --- | --- | --- |
26 | | registerBlockVariation | `rw`,`variation` | Register a block variation
27 | | DomReady | `rw`,`domready` | Setup domReady
28 | | registerFormatType | `rw`,`format` | Register a format type
29 | | registerPlugin | `rw`,`registerPlugin` | Register a plugin for slotfill
30 | | Command Pallette | `rw`,`command` | Register a command
31 |
32 | ### block-editor
33 | | Name | Snippet(s) | Description |
34 | | --- | --- | --- |
35 | | InspectorControls | `rw`,`wp_blockEditor`,`InspectorControls` | Inspector Controls appear in the post settings sidebar when a block is being edited
36 | | RichText.Content | `rw`,`wp_blockEditor`,`block-editor`,`RichText` | Inserts a RichText component.
37 | | RichText | `rw`,`wp_blockEditor`,`block-editor`,`RichText` | Inserts a RichText component.
38 |
39 | ### blocks
40 | | Name | Snippet(s) | Description |
41 | | --- | --- | --- |
42 | | getCategories | `rw`,`wp_blocks`,`getCategories` | Returns all the available block categories.
43 | | setCategories | `rw`,`wp_blocks`,`setCategories` | Returns an action object used to set block categories.
44 | | setDefaultBlockName | `rw`,`wp_blocks`,`setDefaultBlockName` | Returns an action object used to set the default block name.
45 |
46 | ### components
47 | | Name | Snippet(s) | Description |
48 | | --- | --- | --- |
49 | | Alignment Matrix Control | `rw`,`wp_components`,`components`,`AlignmentMatrixControl` | AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.
50 | | AnglePickerControl | `rw`,`wp_components`,`components`,`AnglePickerControl` | AnglePickerControl is a React component to render a UI that allows users to pick an angle. Users can choose an angle in a visual UI with the mouse by dragging an angle indicator inside a circle or by directly inserting the desired angle in a text field.
51 | | Animate | `rw`,`wp_components`,`components`,`Animate` | Simple interface to introduce animations to components.
52 | | Autocomplete | `rw`,`wp_components`,`components`,`Autocomplete` | This component is used to provide autocompletion support for a child input component.
53 | | BaseControl | `rw`,`wp_components`,`components`,`BaseControl` | BaseControl component is used to generate labels and help text for components handling user inputs.
54 | | ButtonGroup | `rw`,`wp_components`,`components`,`ButtonGroup` | ButtonGroup can be used to group any related buttons together. To emphasize related buttons, a group should share a common container.
55 | | Button | `wp.components`,`components`,`Button` | Buttons let users take actions and make choices with a single click or tap.
56 | | CheckboxControl | `wp.components`,`components`,`CheckboxControl` | Checkboxes allow the user to select one or more items from a set.
57 | | ColorIndicator | `wp.components`,`components`,`ColorIndicator` | Displays a color.
58 | | ColorPalette | `wp.components`,`components`,`ColorPalette` | Display a color palette
59 | | ColorPicker | `wp.components`,`components`,`ColorPicker` | ColorPicker is a color picking component based on react-colorful. It lets you pick a color visually or by manipulating the individual RGB(A), HSL(A) and Hex(8) color values.
60 | | ComboboxControl | `wp.components`,`components`,`ComboboxControl` | ComboboxControl is an enhanced version of a SelectControl, with the addition of being able to search for options using a search input.
61 | | CustomSelectControl | `wp.components`,`components`,`CustomSelectControl` | CustomSelectControl allows users to select an item from a single-option menu just like SelectControl, with the addition of being able to provide custom styles for each item in the menu. This means it does not use a native , so should only be used if the custom styling is necessary.
62 | | Dashicon | `wp.components`,`components`,`Dashicon` | add description
63 | | DateTimePicker | `wp.components`,`components`,`DateTimePicker` | DateTimePicker is a React component that renders a calendar and clock for date and time selection. The calendar and clock components can be accessed individually using the DatePicker and TimePicker components respectively.
64 | | Disabled | `wp.components`,`components`,`Disabled` | Disabled is a component which disables descendant tabbable elements and prevents pointer interaction.
65 | | Draggable | `wp.components`,`components`,`Draggable` | Draggable is a Component that provides a way to set up a a cross-browser (including IE) customisable drag image and the transfer data for the drag event. It decouples the drag handle and the element to drag. Use it by wrapping the component that will become the drag handle and providing the DOM ID of the element to drag.
66 | | DropdownMenu | `wp.components`,`components`,`DropdownMenu` | The DropdownMenu displays a list of actions (each contained in a MenuItem, MenuItemsChoice, or MenuGroup) in a compact way. It appears in a Popover after the user has interacted with an element (a button or icon) or when they perform a specific action.
67 | | Dropdown | `wp.components`,`components`,`Dropdown` | Dropdown is a React component to render a button that opens a floating content modal when clicked.
68 | | Dropzone | `wp.components`,`components`,`Dropzone` | DropZone is a Component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.
69 | | DuotonePicker & DuotoneSwatch | `wp.components`,`components`,`DuotonePicker`,`DuotoneSwatch` | add description
70 | | ExternalLink | `wp.components`,`components`,`ExternalLink` | add description
71 | | FocalPointPicker | `wp.components`,`components`,`FocalPointPicker` | Focal Point Picker is a component which creates a UI for identifying the most important visual point of an image.
72 | | FontSizePicker | `wp.components`,`components`,`FontSizePicker` | FontSizePicker is a React component that renders a UI that allows users to select a font size
73 | | FormFileUpload | `wp.components`,`components`,`FormFileUpload` | Renders a FormFileUpload
74 | | FormToggle | `wp.components`,`components`,`FormToggle` | Renders a FormToggle
75 | | FormTokenField | `wp.components`,`components`,`FormTokenField` | A FormTokenField is a field similar to the tags and categories fields in the interim editor chrome, or the "to" field in Mail on OS X. Tokens can be entered by typing them or selecting them from a list of suggested tokens.
76 | | Guide | `wp.components`,`components`,`Guide` | Guide is a React component that renders a user guide in a modal.
77 | | PanelBody | `rw`,`wp_components`,`PanelBody` | The PanelBody creates a collapsible container that can be toggled open or closed.
78 |
79 | ### core-data
80 | | Name | Snippet(s) | Description |
81 | | --- | --- | --- |
82 | | getCurrentUser | `rw`,`wp_coreData`,`getCurrentUser` | Returns the current user
83 |
84 | ### data
85 | | Name | Snippet(s) | Description |
86 | | --- | --- | --- |
87 | | getEmbedPreview | `rw`,`wp_data`,`getEmbedPreview` | add description
88 |
89 | ### js
90 | | Name | Snippet(s) | Description |
91 | | --- | --- | --- |
92 | | requestAnimationFrame | `rw`,`animate` | requestAnimationFrame
93 |
94 | ### json
95 | | Name | Snippet(s) | Description |
96 | | --- | --- | --- |
97 | | Generate block.json file | `rw`,`wp`,`json`,`block` | Generates the contents of a block.json file
98 | | Generate a basic theme.json file | `rw`,`wp`,`json`,`theme` | Generates the contents of a theme.json file
99 |
100 | ### notices
101 | | Name | Snippet(s) | Description |
102 | | --- | --- | --- |
103 | | createErrorNotice | `rw`,`wp_notices`,`createErrorNotice` | Returns an action object used in signalling that an error notice is to be created. Refer to createNotice for options documentation.
104 | | createInfoNotice | `rw`,`wp_notices`,`wp_data`,`createInfoNotice` | Returns an action object used in signalling that an info notice is to be created. Refer to createNotice for options documentation.
105 | | createNotice | `rw`,`wp_notices`,`wp_data`,`createNotice` | Returns an action object used in signalling that a notice is to be created.
106 | | createSuccessNotice | `rw`,`wp_notices`,`wp_data`,`createSuccessNotice` | Returns an action object used in signalling that a success notice is to be created. Refer to createNotice for options documentation.
107 | | createWarningNotice | `rw`,`wp_notices`,`wp_data`,`createWarningNotice` | Returns an action object used in signalling that a warning notice is to be created. Refer to createNotice for options documentation.
108 | | getNotices | `rw`,`wp_notices`,`wp_data`,`getNotices` | Returns all notices as an array, optionally for a given context. Defaults to the global context.
109 | | removeNotice | `rw`,`wp_notices`,`wp_data`,`removeNotice` | Returns an action object used in signalling that a notice is to be removed.
110 |
111 | ### php
112 | | Name | Snippet(s) | Description |
113 | | --- | --- | --- |
114 | | Admin Screen | `rw`,`screen` | Register a new admin screen
115 | | Insert WordPress debug constants | `rw`,`wp`,`debug` | Inserts the WP_DEBUG and WP_DEBUG_LOG and other debug related constants.
116 | | Enqueue a script from a plugin in the block editor | `rw`,`wp`,`php`,`enqueue-from-plugin` | Enqueues a script in the block editor stored in a plugin
117 | | Enqueue a script from a theme in the block editor | `rw`,`wp`,`php`,`enqueue-from-plugin` | Enqueues a script in the block editor stored in a theme
118 | | Enqueue a viewScript file | `rw`,`wp`,`enqueue`,`viewScript` | Enqueue the viewScript file for a dynamic block
119 |
120 | ### structure
121 | | Name | Snippet(s) | Description |
122 | | --- | --- | --- |
123 | | Block Edit component | `rw`,`block`,`edit` | Create an Edit component for custom block development.
124 | | Block Save component | `rw`,`block`,`save` | Create a Save component for custom block development.
125 | | Retrieve from the WordPress datastore | `rw`,`wp`,`getEntityRecords`,`get-data` | Add getEntityRecords selector with isLoading and invalidateResolution.
126 |
127 | ### webpack
128 | | Name | Snippet(s) | Description |
129 | | --- | --- | --- |
130 | | Custom entry points | `rw`,`webpack`,`entrypoints` | Create a webpack config with custom entry points
131 |
132 |
133 |
134 |
135 | ## Development
136 |
137 | 1. Install the dependencies: `npm install`
138 | 2. DO WORK!
139 | 3. Generate the updated snippets: `npm run generate`
140 |
141 | The snippets are stored in the snippet-data directory in a subdirectory that corresponds to the snippet's category. For example, the components that are part of the `@wordpress/components` package are stored in the `components` directory, PHP related snippets are stored in the `php` directory and so on.
142 |
143 | To add a new snippet category, simply add a new directory to the snippet-data directory and update the package.json file to include the new category to the `contributes.snippets` array.
144 |
145 | To add a new snippet to any category, create a new file called {snippet}.snip. Please use a name that makes it clear what the snippet represents. For example, a snippet for the ` ` component would be named `button.snip`.
146 |
147 | Once the file has been created, there is a custom snippet for the workspace that will automatically add the snippet to the snippet file. Trigger it by typing `snip` in the new file. Please use this scaffold as a starting point to keep the format consistent.
148 |
149 | The .snip files use front-matter to store the data about the snippet
150 |
151 | Raw snippet file:
152 |
153 | ```plaintext
154 | ---
155 | title: Alignment Matrix Control
156 | prefix: wp.components|AlignmentMatrixControl
157 | description: AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.
158 | ---
159 |
160 | $LINE_COMMENT Reference: https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/alignment-matrix-control",
161 |
162 | import { AlignmentMatrixControl } from '@wordpress/components';
163 |
164 |
165 | ```
166 |
167 | Converts to in snippet file:
168 |
169 | ```json
170 | "Alignment Matrix Control": {
171 | "prefix": [
172 | "wp.components",
173 | "AlignmentMatrixControl"
174 | ],
175 | "description": "AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.",
176 | "body": [
177 | "$LINE_COMMENT Reference: https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/alignment-matrix-control\",",
178 | "",
179 | "import { AlignmentMatrixControl } from '@wordpress/components';",
180 | "",
181 | " "
182 | ]
183 | },
184 | ```
185 |
186 | Note that the prefix is pipe-delimited and is converted to an array in the json.
187 |
188 | Inserted Snippet:
189 |
190 | ```jsx
191 | // Reference: https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/alignment-matrix-control",
192 |
193 | import { AlignmentMatrixControl } from '@wordpress/components';
194 |
195 | ;
196 | ```
197 |
--------------------------------------------------------------------------------
/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ryanwelcher/modern-wordpress-development-snippets/4c14992672cdc42e38ca7979b975b96017e1dd3c/assets/icon.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "modern-wordpress-development-snippets",
3 | "displayName": "Modern WordPress Developer Snippets",
4 | "description": "Snippets for working with WordPress and Gutenberg",
5 | "publisher": "ryanwelcher",
6 | "author": {
7 | "name": "Ryan Welcher",
8 | "email": "me@ryanwelcher.com",
9 | "url": "https://www.ryanwelcher.com"
10 | },
11 | "license": "MIT",
12 | "repository": {
13 | "type": "git",
14 | "url": "https://github.com/ryanwelcher/modern-wordpress-development-snippets.git"
15 | },
16 | "version": "1.1.5",
17 | "engines": {
18 | "vscode": "^1.49.0"
19 | },
20 | "icon": "assets/icon.png",
21 | "scripts": {
22 | "generate": "npm run generate:snippets && npm run generate:readme",
23 | "generate:snippets": "node ./src/generate-snippets.js",
24 | "generate:readme": "node ./src/generate-readme.js",
25 | "lint": "npm run lint:data && npm run lint:js",
26 | "lint:js": "eslint --ext .js src",
27 | "lint:data": "node ./src/lint-snippet-data.js",
28 | "prepackage": "rimraf *.vsix",
29 | "package": "vsce package",
30 | "load": "code --install-extension *.vsix",
31 | "refresh-extension": "npm run package && npm run load"
32 | },
33 | "categories": [
34 | "Snippets"
35 | ],
36 | "contributes": {
37 | "snippets": [
38 | {
39 | "language": "php",
40 | "path": "./snippets/php.json"
41 | },
42 | {
43 | "language": "json",
44 | "path": "./snippets/json.json"
45 | },
46 | {
47 | "language": "javascript",
48 | "path": "./snippets/webpack.json"
49 | },
50 | {
51 | "language": "javascript",
52 | "path": "./snippets/js.json"
53 | },
54 | {
55 | "language": "javascriptreact",
56 | "path": "./snippets/js.json"
57 | },
58 | {
59 | "language": "typescript",
60 | "path": "./snippets/js.json"
61 | },
62 | {
63 | "language": "typescriptreact",
64 | "path": "./snippets/js.json"
65 | },
66 | {
67 | "language": "javascript",
68 | "path": "./snippets/data.json"
69 | },
70 | {
71 | "language": "javascriptreact",
72 | "path": "./snippets/data.json"
73 | },
74 | {
75 | "language": "typescript",
76 | "path": "./snippets/data.json"
77 | },
78 | {
79 | "language": "typescriptreact",
80 | "path": "./snippets/data.json"
81 | },
82 | {
83 | "language": "javascript",
84 | "path": "./snippets/api.json"
85 | },
86 | {
87 | "language": "javascriptreact",
88 | "path": "./snippets/api.json"
89 | },
90 | {
91 | "language": "typescript",
92 | "path": "./snippets/api.json"
93 | },
94 | {
95 | "language": "typescriptreact",
96 | "path": "./snippets/api.json"
97 | },
98 | {
99 | "language": "jsx",
100 | "path": "./snippets/data.json"
101 | },
102 | {
103 | "language": "javascript",
104 | "path": "./snippets/core-data.json"
105 | },
106 | {
107 | "language": "javascriptreact",
108 | "path": "./snippets/core-data.json"
109 | },
110 | {
111 | "language": "typescript",
112 | "path": "./snippets/core-data.json"
113 | },
114 | {
115 | "language": "typescriptreact",
116 | "path": "./snippets/core-data.json"
117 | },
118 | {
119 | "language": "javascript",
120 | "path": "./snippets/components.json"
121 | },
122 | {
123 | "language": "javascriptreact",
124 | "path": "./snippets/components.json"
125 | },
126 | {
127 | "language": "typescript",
128 | "path": "./snippets/components.json"
129 | },
130 | {
131 | "language": "typescriptreact",
132 | "path": "./snippets/components.json"
133 | },
134 | {
135 | "language": "jsx",
136 | "path": "./snippets/components.json"
137 | },
138 | {
139 | "language": "javascript",
140 | "path": "./snippets/structure.json"
141 | },
142 | {
143 | "language": "javascriptreact",
144 | "path": "./snippets/structure.json"
145 | },
146 | {
147 | "language": "typescript",
148 | "path": "./snippets/structure.json"
149 | },
150 | {
151 | "language": "typescriptreact",
152 | "path": "./snippets/structure.json"
153 | },
154 | {
155 | "language": "jsx",
156 | "path": "./snippets/structure.json"
157 | },
158 | {
159 | "language": "javascript",
160 | "path": "./snippets/notices.json"
161 | },
162 | {
163 | "language": "javascriptreact",
164 | "path": "./snippets/notices.json"
165 | },
166 | {
167 | "language": "typescript",
168 | "path": "./snippets/notices.json"
169 | },
170 | {
171 | "language": "typescriptreact",
172 | "path": "./snippets/notices.json"
173 | },
174 | {
175 | "language": "javascript,",
176 | "path": "./snippets/block-editor.json"
177 | },
178 | {
179 | "language": "javascriptreact",
180 | "path": "./snippets/block-editor.json"
181 | },
182 | {
183 | "language": "typescript",
184 | "path": "./snippets/block-editor.json"
185 | },
186 | {
187 | "language": "typescriptreact",
188 | "path": "./snippets/block-editor.json"
189 | },
190 | {
191 | "language": "jsx",
192 | "path": "./snippets/block-editor.json"
193 | },
194 | {
195 | "language": "javascript",
196 | "path": "./snippets/blocks.json"
197 | },
198 | {
199 | "language": "javascriptreact",
200 | "path": "./snippets/blocks.json"
201 | },
202 | {
203 | "language": "typescript",
204 | "path": "./snippets/blocks.json"
205 | },
206 | {
207 | "language": "typescriptreact",
208 | "path": "./snippets/blocks.json"
209 | }
210 | ]
211 | },
212 | "prettier": "@wordpress/prettier-config",
213 | "devDependencies": {
214 | "@wordpress/eslint-plugin": "^12.7.0",
215 | "@wordpress/scripts": "^23.3.0",
216 | "eslint-plugin-prettier": "^4.0.0",
217 | "glob": "^7.2.0",
218 | "gray-matter": "^4.0.3",
219 | "prettier": "npm:wp-prettier@2.6.2",
220 | "rimraf": "^3.0.2",
221 | "vsce": "^2.10.0"
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/snippet-data/api/block-variations.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: registerBlockVariation
3 | prefix: rw|variation
4 | description: Register a block variation
5 | ---
6 |
7 | import { registerBlockVariation } from '@wordpress/blocks';
8 |
9 | registerBlockVariation( '${1:namespace/blockname}', {
10 | name: 'paragraph-red',
11 | title: 'Red Paragraph',
12 | attributes: {
13 | textColor: 'vivid-red',
14 | },
15 | isActive: [ 'textColor' ],
16 | scope: [ 'inserter', 'blocks' ],
17 | } );
18 |
--------------------------------------------------------------------------------
/snippet-data/api/dom-ready.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: DomReady
3 | prefix: rw|domready
4 | description: Setup domReady
5 | ---
6 |
7 | import domReady from '@wordpress/dom-ready';
8 |
9 |
10 | domReady( () => {
11 | // This code runs after the DOM is loaded.
12 | } );
13 |
--------------------------------------------------------------------------------
/snippet-data/api/format-api.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: registerFormatType
3 | prefix: rw|format
4 | description: Register a format type
5 | ---
6 |
7 | import { registerFormatType, toggleFormat } from '@wordpress/rich-text';
8 | import { RichTextToolbarButton } from '@wordpress/block-editor';
9 |
10 | const MyCustomButton = ( { isActive, onChange, value } ) => {
11 | return (
12 | {
16 | onChange(
17 | toggleFormat( value, {
18 | type: 'my-custom-format/sample-output',
19 | } )
20 | );
21 | } }
22 | isActive={ isActive }
23 | />
24 | );
25 | };
26 |
27 | registerFormatType( '${1:format}', {
28 | title: 'Sample output',
29 | tagName: '${2:tag}',
30 | className: '${1:class},
31 | edit: MyCustomButton,
32 | } );
33 |
34 |
--------------------------------------------------------------------------------
/snippet-data/api/plugin.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: registerPlugin
3 | prefix: rw|registerPlugin
4 | description: Register a plugin for slotfill
5 | ---
6 | import { registerPlugin } from '@wordpress/plugins';
7 | import {
8 | PluginSidebar,
9 | PluginSidebarMoreMenuItem,
10 | PluginPrePublishPanel,
11 | PluginPostStatusInfo,
12 | PluginPostPublishPanel,
13 | PluginMoreMenuItem,
14 | PluginDocumentSettingPanel,
15 | PluginBlockSettingsMenuItem,
16 | } from '@wordpress/editor';
17 | import { PanelBody } from '@wordpress/components';
18 |
19 | registerPlugin( '${1:plugin}', {
20 | render: () => {},
21 | } );
22 |
--------------------------------------------------------------------------------
/snippet-data/api/register-command.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Command Pallette
3 | prefix: rw|command
4 | description: Register a command
5 | ---
6 |
7 | import { store as commandsStore } from '@wordpress/commands';
8 | import { dispatch, select } from '@wordpress/data';
9 | import { __ } from '@wordpress/i18n';
10 |
11 | function doWork() {
12 | }
13 |
14 | dispatch( commandsStore ).registerCommand( {
15 | name: '${1:command name}',
16 | label: __( '${1:label}' ),
17 | callback: ( { close } ) => {
18 | doWork();
19 | close();
20 | },
21 | } );
22 |
--------------------------------------------------------------------------------
/snippet-data/block-editor/inspector-controls.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: InspectorControls
3 | prefix: rw|wp_blockEditor|InspectorControls
4 | description: Inspector Controls appear in the post settings sidebar when a block is being edited
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/block-editor/src/components/inspector-controls
8 |
9 | import { InspectorControls } from '@wordpress/block-editor';
10 |
11 |
12 | $TM_SELECTED_TEXT
13 |
14 |
--------------------------------------------------------------------------------
/snippet-data/block-editor/rich-text-content.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: RichText.Content
3 | prefix: rw|wp_blockEditor|block-editor|RichText
4 | description: Inserts a RichText component.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/README.md
8 |
9 | import { RichText } from '@wordpress/block-editor';
10 |
11 |
12 |
--------------------------------------------------------------------------------
/snippet-data/block-editor/rich-text.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: RichText
3 | prefix: rw|wp_blockEditor|block-editor|RichText
4 | description: Inserts a RichText component.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/README.md
8 |
9 | import { RichText } from '@wordpress/block-editor';
10 |
11 | setAttributes( { content } ) }
14 | ${3:tagName="${4:div}"}
15 | ${4:placeholder="${5:Placeholder Text"}
16 | ${6:multiline={${7:boolean|string}}}
17 | ${8:onSplit={(value) => console.log(value)}}
18 | ${9:onReplace]={(blocks) => console.log(blocks)}}
19 | ${10:onMerge]={(forward) => console.log(forward)}}
20 | ${11:onRemove]={(forward) => console.log(forward)}}
21 | ${12:allowedFormats]={[
22 | 'core/bold',
23 | 'core/code',
24 | 'core/image',
25 | 'core/italic',
26 | 'core/link',
27 | 'core/strikethrough',
28 | 'core/underline',
29 | 'core/text-color',
30 | 'core/subscript',
31 | 'core/superscript',
32 | 'core/keyboard',
33 | ]
34 | }}
35 | ${13:withoutInteractiveFormatting={${14:true|false}}}
36 | ${15:isSelected={${16:true|false}}}
37 | ${17:autocompleters={${18:[]}}}
38 | ${19:preserveWhiteSpace={${20:true|false}}}
39 | ${21:className="${22:class-name}"}
40 | />
41 |
--------------------------------------------------------------------------------
/snippet-data/blocks/get-categories.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: getCategories
3 | prefix: rw|wp_blocks|getCategories
4 | description: Returns all the available block categories.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#getcategories
8 |
9 | import { store as blocksStore } from '@wordpress/blocks';
10 | import { useSelect, useDispatch } from '@wordpress/data';
11 |
12 | const ExampleComponent = () => {
13 | const blockCategories = useSelect( ( select ) =>
14 | select( blocksStore ).getCategories()
15 | );
16 | const { setCategories } = useDispatch( blocksStore );
17 |
18 | return (
19 |
21 | setCategories( [
22 | ...blockCategories,
23 | { title: 'Custom Category', slug: 'custom-category' },
24 | ] )
25 | }
26 | >
27 | { __( 'Add a new custom block category' ) }
28 |
29 | );
30 | };
31 |
--------------------------------------------------------------------------------
/snippet-data/blocks/set-categories.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: setCategories
3 | prefix: rw|wp_blocks|setCategories
4 | description: Returns an action object used to set block categories.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#setcategories
8 |
9 | import { store as blocksStore } from '@wordpress/blocks';
10 | import { useSelect, useDispatch } from '@wordpress/data';
11 |
12 | const ExampleComponent = () => {
13 | const blockCategories = useSelect( ( select ) =>
14 | select( blocksStore ).getCategories()
15 | );
16 | const { setCategories } = useDispatch( blocksStore );
17 |
18 | return (
19 |
21 | setCategories( [
22 | ...blockCategories,
23 | { title: 'Custom Category', slug: 'custom-category' },
24 | ] )
25 | }
26 | >
27 | { __( 'Add a new custom block category' ) }
28 |
29 | );
30 | };
31 |
--------------------------------------------------------------------------------
/snippet-data/blocks/set-default-block-name.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: setDefaultBlockName
3 | prefix: rw|wp_blocks|setDefaultBlockName
4 | description: Returns an action object used to set the default block name.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#setdefaultblockname
8 |
9 | import { store as blocksStore } from '@wordpress/blocks';
10 | import { useDispatch } from '@wordpress/data';
11 |
12 | const ExampleComponent = () => {
13 | const { setDefaultBlockName } = useDispatch( blocksStore );
14 |
15 | return (
16 | setDefaultBlockName( 'core/heading' ) }>
17 | { __( 'Set the default block to Heading' ) }
18 |
19 | );
20 | };
21 |
--------------------------------------------------------------------------------
/snippet-data/components/alignment-matrix-control.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Alignment Matrix Control
3 | prefix: rw|wp_components|components|AlignmentMatrixControl
4 | description: AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.
5 | ---
6 |
7 | $LINE_COMMENT Reference: https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/alignment-matrix-control",
8 |
9 | import { AlignmentMatrixControl } from '@wordpress/components';
10 |
11 |
12 |
--------------------------------------------------------------------------------
/snippet-data/components/angle-picker-control.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: AnglePickerControl
3 | prefix: rw|wp_components|components|AnglePickerControl
4 | description: AnglePickerControl is a React component to render a UI that allows users to pick an angle. Users can choose an angle in a visual UI with the mouse by dragging an angle indicator inside a circle or by directly inserting the desired angle in a text field.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/angle-picker-control
8 |
9 | import { useState } from '@wordpress/element';
10 | import { AnglePickerControl } from '@wordpress/components';
11 |
12 | const MyAnglePicker = () => {
13 | const [ angle, setAngle ] = useState();
14 | return ;
15 | };
16 |
--------------------------------------------------------------------------------
/snippet-data/components/animate.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Animate
3 | prefix: rw|wp_components|components|Animate
4 | description: Simple interface to introduce animations to components.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/animate
8 |
9 | import { Animate } from '@wordpress/components';
10 |
11 | const MyAnimatedNotice = () => (
12 |
13 | { ( { className } ) => (
14 |
15 | Animation finished.
16 |
17 | ) }
18 |
19 | );
20 |
--------------------------------------------------------------------------------
/snippet-data/components/autocomplete.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Autocomplete
3 | prefix: rw|wp_components|components|Autocomplete
4 | description: This component is used to provide autocompletion support for a child input component.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/autocomplete
8 |
9 | import { Autocomplete } from '@wordpress/components';
10 |
11 | const MyAutocomplete = () => {
12 | const autocompleters = [
13 | {
14 | name: 'fruit',
15 | // The prefix that triggers this completer
16 | triggerprefix: rw|'~',
17 | // The option data
18 | options: [
19 | { visual: '🍎', name: 'Apple', id: 1 },
20 | { visual: '🍊', name: 'Orange', id: 2 },
21 | { visual: '🍇', name: 'Grapes', id: 3 },
22 | ],
23 | // Returns a label for an option like "🍊 Orange"
24 | getOptionLabel: ( option ) => (
25 |
26 | { option.visual }
27 | { option.name }
28 |
29 | ),
30 | // Declares that options should be matched by their name
31 | getOptionKeywords: ( option ) => [ option.name ],
32 | // Declares that the Grapes option is disabled
33 | isOptionDisabled: ( option ) => option.name === 'Grapes',
34 | // Declares completions should be inserted as abbreviations
35 | getOptionCompletion: ( option ) => (
36 | { option.visual }
37 | ),
38 | },
39 | ];
40 |
41 | return (
42 |
43 |
44 | { ( { isExpanded, listBoxId, activeId } ) => (
45 |
53 | ) }
54 |
55 |
Type ~ for triggering the autocomplete.
56 |
57 | );
58 | };
59 |
--------------------------------------------------------------------------------
/snippet-data/components/base-control.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: BaseControl
3 | prefix: rw|wp_components|components|BaseControl
4 | description: BaseControl component is used to generate labels and help text for components handling user inputs.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/base-control
8 |
9 | import { BaseControl } from '@wordpress/components';
10 |
11 | const MyBaseControl = () => (
12 |
13 |
14 |
15 | );
16 |
--------------------------------------------------------------------------------
/snippet-data/components/button-group.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ButtonGroup
3 | prefix: rw|wp_components|components|ButtonGroup
4 | description: ButtonGroup can be used to group any related buttons together. To emphasize related buttons, a group should share a common container.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/button-group
8 |
9 | import { Button, ButtonGroup } from '@wordpress/components';
10 |
11 | const MyButtonGroup = () => (
12 |
13 | Button 1
14 | Button 2
15 |
16 | );
17 |
--------------------------------------------------------------------------------
/snippet-data/components/button.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Button
3 | prefix: wp.components|components|Button
4 | description: Buttons let users take actions and make choices with a single click or tap.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/button
8 |
9 | import { Button } from '@wordpress/components';
10 |
11 | const MyButton = () => Click me! ;
12 |
--------------------------------------------------------------------------------
/snippet-data/components/checkbox-control.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: CheckboxControl
3 | prefix: wp.components|components|CheckboxControl
4 | description: Checkboxes allow the user to select one or more items from a set.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/checkbox-control
8 |
9 | import { CheckboxControl } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyCheckboxControl = () => {
13 | const [ isChecked, setChecked ] = useState( true );
14 | return (
15 |
21 | );
22 | };
23 |
--------------------------------------------------------------------------------
/snippet-data/components/color-indicator.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ColorIndicator
3 | prefix: wp.components|components|ColorIndicator
4 | description: Displays a color.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-indicator
8 |
9 | import { ColorIndicator } from '@wordpress/components';
10 |
11 | const MyColorIndicator = () => ;
12 |
--------------------------------------------------------------------------------
/snippet-data/components/color-palette.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ColorPalette
3 | prefix: wp.components|components|ColorPalette
4 | description: Display a color palette
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-palette
8 |
9 | import { ColorPalette } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyColorPalette = () => {
13 | const [ color, setColor ] = useState ( '#f00' )
14 | const colors = [
15 | { name: 'red', color: '#f00' },
16 | { name: 'white', color: '#fff' },
17 | { name: 'blue', color: '#00f' },
18 | ];
19 |
20 | return (
21 | setColor( color ) }
25 | />
26 | );
27 | } );
28 |
--------------------------------------------------------------------------------
/snippet-data/components/color-picker.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ColorPicker
3 | prefix: wp.components|components|ColorPicker
4 | description: ColorPicker is a color picking component based on react-colorful. It lets you pick a color visually or by manipulating the individual RGB(A), HSL(A) and Hex(8) color values.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-picker
8 |
9 | import { ColorPicker } from '@wordpress/components/ui';
10 |
11 | function Example() {
12 | const [color, setColor] = useState();
13 | return (
14 |
20 | );
21 | }
22 |
--------------------------------------------------------------------------------
/snippet-data/components/combobox-control.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ComboboxControl
3 | prefix: wp.components|components|ComboboxControl
4 | description: ComboboxControl is an enhanced version of a SelectControl, with the addition of being able to search for options using a search input.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/combobox-control
8 |
9 | /**
10 | * WordPress dependencies
11 | */
12 | import { ComboboxControl } from '@wordpress/components';
13 | import { useState } from '@wordpress/compose';
14 |
15 | const options = [
16 | {
17 | value: 'small',
18 | label: 'Small',
19 | },
20 | {
21 | value: 'normal',
22 | label: 'Normal',
23 | },
24 | {
25 | value: 'large',
26 | label: 'Large',
27 | },
28 | {
29 | value: 'huge',
30 | label: 'Huge',
31 | },
32 | ];
33 |
34 | function MyComboboxControl() {
35 | const [ fontSize, setFontSize ] = useState();
36 | const [ filteredOptions, setFilteredOptions ] = useState( options );
37 | return (
38 |
44 | setFilteredOptions(
45 | options.filter( ( option ) =>
46 | option.label
47 | .toLowerCase()
48 | .startsWith( inputValue.toLowerCase() )
49 | )
50 | )
51 | }
52 | />
53 | );
54 | }
55 |
--------------------------------------------------------------------------------
/snippet-data/components/custom-select-controls.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: CustomSelectControl
3 | prefix: wp.components|components|CustomSelectControl
4 | description: CustomSelectControl allows users to select an item from a single-option menu just like SelectControl, with the addition of being able to provide custom styles for each item in the menu. This means it does not use a native , so should only be used if the custom styling is necessary.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/custom-select-control
8 |
9 | /**
10 | * WordPress dependencies
11 | */
12 | import { CustomSelectControl } from '@wordpress/components';
13 | import { useState } from '@wordpress/element';
14 |
15 | const options = [
16 | {
17 | key: 'small',
18 | name: 'Small',
19 | style: { fontSize: '50%' },
20 | },
21 | {
22 | key: 'normal',
23 | name: 'Normal',
24 | style: { fontSize: '100%' },
25 | },
26 | {
27 | key: 'large',
28 | name: 'Large',
29 | style: { fontSize: '200%' },
30 | },
31 | {
32 | key: 'huge',
33 | name: 'Huge',
34 | style: { fontSize: '300%' },
35 | },
36 | ];
37 |
38 | function MyCustomSelectControl() {
39 | const [ , setFontSize ] = useState();
40 | return (
41 | setFontSize( selectedItem ) }
45 | />
46 | );
47 | }
48 |
49 | function MyControlledCustomSelectControl() {
50 | const [ fontSize, setFontSize ] = useState( options[ 0 ] );
51 | return (
52 | setFontSize( selectedItem ) }
56 | value={ options.find( ( option ) => option.key === fontSize.key ) }
57 | />
58 | );
59 | }
60 |
--------------------------------------------------------------------------------
/snippet-data/components/dashicon.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Dashicon
3 | prefix: wp.components|components|Dashicon
4 | description: add description
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dashicon
8 |
9 | import { Dashicon } from '@wordpress/components';
10 |
11 | const MyDashicon = () => (
12 |
13 |
14 |
15 |
16 |
17 | );
18 |
--------------------------------------------------------------------------------
/snippet-data/components/date-time-picker.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: DateTimePicker
3 | prefix: wp.components|components|DateTimePicker
4 | description: DateTimePicker is a React component that renders a calendar and clock for date and time selection. The calendar and clock components can be accessed individually using the DatePicker and TimePicker components respectively.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/date-time
8 |
9 | import { DateTimePicker } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyDateTimePicker = () => {
13 | const [ date, setDate ] = useState( new Date() );
14 |
15 | return (
16 | setDate( newDate ) }
19 | is12Hour={ true }
20 | />
21 | );
22 | }
23 |
--------------------------------------------------------------------------------
/snippet-data/components/disabled.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Disabled
3 | prefix: wp.components|components|Disabled
4 | description: Disabled is a component which disables descendant tabbable elements and prevents pointer interaction.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/disabled
8 |
9 | import { Button, Disabled, TextControl } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyDisabled = () => {
13 | const [ isDisabled, setIsDisabled ] = useState( true );
14 |
15 | let input = {} } />;
16 | if ( isDisabled ) {
17 | input = { input } ;
18 | }
19 |
20 | const toggleDisabled = () => {
21 | setIsDisabled( ( state ) => ! state );
22 | };
23 |
24 | return (
25 |
26 | { input }
27 |
28 | Toggle Disabled
29 |
30 |
31 | );
32 | };
33 |
--------------------------------------------------------------------------------
/snippet-data/components/draggable.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Draggable
3 | prefix: wp.components|components|Draggable
4 | description: Draggable is a Component that provides a way to set up a a cross-browser (including IE) customisable drag image and the transfer data for the drag event. It decouples the drag handle and the element to drag. Use it by wrapping the component that will become the drag handle and providing the DOM ID of the element to drag.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/draggable
8 |
9 | import { Draggable, Panel, PanelBody } from '@wordpress/components';
10 | import { Icon, more } from '@wordpress/icons';
11 |
12 | const MyDraggable = () => (
13 |
14 |
15 |
16 |
17 | { ( { onDraggableStart, onDraggableEnd } ) => (
18 |
24 |
25 |
26 | ) }
27 |
28 |
29 |
30 |
31 | );
32 |
--------------------------------------------------------------------------------
/snippet-data/components/dropdown-menu.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: DropdownMenu
3 | prefix: wp.components|components|DropdownMenu
4 | description: The DropdownMenu displays a list of actions (each contained in a MenuItem, MenuItemsChoice, or MenuGroup) in a compact way. It appears in a Popover after the user has interacted with an element (a button or icon) or when they perform a specific action.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dropdown-menu
8 |
9 | import { DropdownMenu } from '@wordpress/components';
10 | import {
11 | more,
12 | arrowLeft,
13 | arrowRight,
14 | arrowUp,
15 | arrowDown,
16 | } from '@wordpress/icons';
17 |
18 | const MyDropdownMenu = () => (
19 | console.log( 'up' ),
27 | },
28 | {
29 | title: 'Right',
30 | icon: arrowRight,
31 | onClick: () => console.log( 'right' ),
32 | },
33 | {
34 | title: 'Down',
35 | icon: arrowDown,
36 | onClick: () => console.log( 'down' ),
37 | },
38 | {
39 | title: 'Left',
40 | icon: arrowLeft,
41 | onClick: () => console.log( 'left' ),
42 | },
43 | ] }
44 | />
45 | );
46 |
--------------------------------------------------------------------------------
/snippet-data/components/dropdown.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Dropdown
3 | prefix: wp.components|components|Dropdown
4 | description: Dropdown is a React component to render a button that opens a floating content modal when clicked.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dropdown
8 |
9 | import { Button, Dropdown } from '@wordpress/components';
10 |
11 | const MyDropdown = () => (
12 | (
17 |
22 | Toggle Popover!
23 |
24 | ) }
25 | renderContent={ () => This is the content of the popover.
}
26 | />
27 | );
28 |
--------------------------------------------------------------------------------
/snippet-data/components/dropzone.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Dropzone
3 | prefix: wp.components|components|Dropzone
4 | description: DropZone is a Component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/drop-zone
8 |
9 | import { DropZone } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyDropZone = () => {
13 | const [ hasDropped, setHasDropped ] = useState( false );
14 |
15 | return (
16 |
17 | { hasDropped ? 'Dropped!' : 'Drop something here' }
18 | setHasDropped( true ) }
20 | onHTMLDrop={ () => setHasDropped( true ) }
21 | onDrop={ () => setHasDropped( true ) }
22 | />
23 |
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/snippet-data/components/duotone-picker-swatch.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: DuotonePicker & DuotoneSwatch
3 | prefix: wp.components|components|DuotonePicker|DuotoneSwatch
4 | description: add description
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/duotone-picker
8 |
9 | import { DuotonePicker, DuotoneSwatch } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const DUOTONE_PALETTE = [
13 | { colors: [ '#8c00b7', '#fcff41' ], name: 'Purple and yellow', slug: 'purple-yellow' },
14 | { colors: [ '#000097', '#ff4747' ], name: 'Blue and red', slug: 'blue-red' },
15 | ];
16 |
17 | const COLOR_PALETTE = [
18 | { color: '#ff4747', name: 'Red', slug: 'red' },
19 | { color: '#fcff41', name: 'Yellow', slug: 'yellow' },
20 | { color: '#000097', name: 'Blue', slug: 'blue' },
21 | { color: '#8c00b7', name: 'Purple', slug: 'purple' },
22 | ];
23 |
24 | const Example = () => {
25 | const [ duotone, setDuotone ] = useState( [ '#000000', '#ffffff' ] );
26 | return (
27 | <>
28 |
34 |
35 | >
36 | );
37 | };
38 | `
39 |
--------------------------------------------------------------------------------
/snippet-data/components/external-link.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: ExternalLink
3 | prefix: wp.components|components|ExternalLink
4 | description: add description
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/external-link
8 |
9 | import { ExternalLink } from '@wordpress/components';
10 |
11 | const MyExternalLink = () => (
12 | WordPress.org
13 | );
14 |
--------------------------------------------------------------------------------
/snippet-data/components/focal-point-picker.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: FocalPointPicker
3 | prefix: wp.components|components|FocalPointPicker
4 | description: Focal Point Picker is a component which creates a UI for identifying the most important visual point of an image.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/focal-point-picker
8 |
9 | import { FocalPointPicker } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const Example = () => {
13 | const [ focalPoint, setFocalPoint ] = useState( {
14 | x: 0.5,
15 | y: 0.5,
16 | } );
17 |
18 | const url = '/path/to/image';
19 | const dimensions = {
20 | width: 400,
21 | height: 100,
22 | };
23 |
24 | /* Example function to render the CSS styles based on Focal Point Picker value */
25 | const style = {
26 | backgroundImage: `url(${ url })`,
27 | backgroundPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`,
28 | };
29 |
30 | return (
31 | <>
32 | setFocalPoint( { focalPoint } ) }
37 | />
38 |
39 | >
40 | );
41 | };
42 |
--------------------------------------------------------------------------------
/snippet-data/components/font-size-picker.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: FontSizePicker
3 | prefix: wp.components|components|FontSizePicker
4 | description: FontSizePicker is a React component that renders a UI that allows users to select a font size
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/font-size-picker
8 |
9 | import { FontSizePicker } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 | import { __ } from '@wordpress/i18n';
12 |
13 | const fontSizes = [
14 | {
15 | name: __( 'Small' ),
16 | slug: 'small',
17 | size: 12,
18 | },
19 | {
20 | name: __( 'Big' ),
21 | slug: 'big',
22 | size: 26,
23 | },
24 | ];
25 | const fallbackFontSize = 16;
26 |
27 | const MyFontSizePicker = () => {
28 | const [ fontSize, setFontSize ] = useState( 12 );
29 |
30 | return (
31 | {
36 | setFontSize( newFontSize );
37 | } }
38 | />
39 | );
40 | };
41 |
42 | ...
43 |
44 |
45 |
--------------------------------------------------------------------------------
/snippet-data/components/form-file-upload.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: FormFileUpload
3 | prefix: wp.components|components|FormFileUpload
4 | description: Renders a FormFileUpload
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-file-upload
8 |
9 | import { FormFileUpload } from '@wordpress/components';
10 |
11 | const MyFormFileUpload = () => (
12 | console.log( 'new image' ) }
15 | >
16 | Upload
17 |
18 | );
19 |
--------------------------------------------------------------------------------
/snippet-data/components/form-toggle.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: FormToggle
3 | prefix: wp.components|components|FormToggle
4 | description: Renders a FormToggle
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-toggle
8 |
9 | import { FormToggle } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const MyFormToggle = () => {
13 | const [ isChecked, setChecked ] = useState( true );
14 |
15 | setChecked( ( state ) => ! state ) }
18 | />
19 | };
20 |
--------------------------------------------------------------------------------
/snippet-data/components/form-token-field.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: FormTokenField
3 | prefix: wp.components|components|FormTokenField
4 | description: A FormTokenField is a field similar to the tags and categories fields in the interim editor chrome, or the "to" field in Mail on OS X. Tokens can be entered by typing them or selecting them from a list of suggested tokens.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-token-field
8 |
9 | import { FormTokenField } from '@wordpress/components';
10 | import { useState } from '@wordpress/element';
11 |
12 | const continents = [
13 | 'Africa',
14 | 'America',
15 | 'Antarctica',
16 | 'Asia',
17 | 'Europe',
18 | 'Oceania',
19 | ];
20 |
21 | const MyFormTokenField = () => {
22 | const [ selectedContinents, setSelectedContinents ] = useState( [] );
23 |
24 | return(
25 | setSelectedContinents( tokens ) }
29 | />
30 | );
31 | };
32 |
--------------------------------------------------------------------------------
/snippet-data/components/guide.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Guide
3 | prefix: wp.components|components|Guide
4 | description: Guide is a React component that renders a user guide in a modal.
5 | ---
6 |
7 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/guide
8 |
9 | function MyTutorial() {
10 | const [ isOpen, setIsOpen ] = useState( true );
11 |
12 | if ( ! isOpen ) {
13 | return null;
14 | }
15 |
16 | return (
17 | setIsOpen( false ) }
19 | pages={ [
20 | {
21 | content: Welcome to the ACME Store!
,
22 | },
23 | {
24 | image: ,
25 | content: (
26 |
27 | Click Add to Cart to buy a product.
28 |
29 | ),
30 | },
31 | ] }
32 | />
33 | );
34 | }
35 |
--------------------------------------------------------------------------------
/snippet-data/components/panel-body.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: PanelBody
3 | prefix: rw|wp_components|PanelBody
4 | description: The PanelBody creates a collapsible container that can be toggled open or closed.
5 | ---
6 |
7 | import { PanelBody} from '@wordpress/components';
8 |
9 | $LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/panel#panelbody
10 |
11 | {console.log('Toggled');}}}
17 | ${9:initialOpen={${10:true|false}}}
18 | ${11:children={(opened) => {console.log(opened);}}}
19 | ${12:buttonProps={${13:{}}}}
20 | >
21 | $TM_SELECTED_TEXT
22 |
23 |
--------------------------------------------------------------------------------
/snippet-data/core-data/get-current-user.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: getCurrentUser
3 | prefix: rw|wp_coreData|getCurrentUser
4 | description: Returns the current user
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core/#getcurrentuser
8 |
9 | import { store as coreDataStore } from '@wordpress/core-data';
10 | import { useSelect } from '@wordpress/data';
11 | import { sprintf, __ } from '@wordpress/i18n';
12 |
13 | const ExampleComponent = () => {
14 | const currentUser = useSelect( ( select ) =>
15 | select( coreDataStore ).getCurrentUser()
16 | );
17 |
18 | return currentUser ? (
19 | { sprintf( __( 'Hello, %s!' ), currentUser.name ) }
20 | ) : (
21 | { __( 'Loading User information…' ) }
22 | );
23 | };
24 |
--------------------------------------------------------------------------------
/snippet-data/data/get-embed-preview.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: getEmbedPreview
3 | prefix: rw|wp_data|getEmbedPreview
4 | description: add description
5 | ---
6 |
7 | $LINE_COMMENT @see reference-link
8 | import { store as coreDataStore } from '@wordpress/core-data';
9 | import { useSelect } from '@wordpress/data';
10 |
11 | const embedPreview = useSelect( ( select ) =>
12 | select( coreDataStore ).getEmbedPreview( {$1} )
13 | );
14 |
--------------------------------------------------------------------------------
/snippet-data/js/requestAnimationFrame.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: requestAnimationFrame
3 | prefix: rw|animate
4 | description: requestAnimationFrame
5 | ---
6 |
7 | function loop() {
8 | // Work to be done each loop.
9 |
10 | // Update this to be a real condition
11 | if ( true ) {
12 | requestAnimationFrame( showTime );
13 | }
14 | }
15 |
16 | // kick it all off
17 | requestAnimationFrame( loop );
18 |
--------------------------------------------------------------------------------
/snippet-data/json/block.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Generate block.json file
3 | prefix: rw|wp|json|block
4 | description: Generates the contents of a block.json file
5 | ---
6 |
7 | {
8 | "apiVersion": 2,
9 | "name": "${1:example-name}",
10 | "title": "${2:Title}",
11 | "category": "${3:common}",
12 | "description": "${4:Description}",
13 | "text-domain": "${5:example-text-domain}",
14 | "icon": "${6:feedback}",
15 | "attributes": {},
16 | "keywords": [],
17 | "version": "${7:0.0.1}",
18 | "providesContext": {},
19 | "usesContext": [],
20 | "styles": [],
21 | "example": {
22 | "attributes": {}
23 | },
24 | "supports": {},
25 | "editorScript": "${8:file:./build/index.js}",
26 | "script": "${9:file:./build/script.js}",
27 | "editorStyle": "${10:file:./build/index.css}",
28 | "style": "${11:file:./build/index.css}",
29 | "viewScript" : "${12:file:./build/view.js}",
30 | "render" : "${13:file:./build/template.php}"
31 | }
32 |
--------------------------------------------------------------------------------
/snippet-data/json/theme.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Generate a basic theme.json file
3 | prefix: rw|wp|json|theme
4 | description: Generates the contents of a theme.json file
5 | ---
6 | {
7 | "$schema": "http://schemas.wp.org/trunk/theme.json",
8 | "version": 2,
9 | "settings": {
10 | "layout": {
11 | "contentSize": "${1:650px}",
12 | "wideSize": "${2:1000px}"
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/snippet-data/notices/create-error-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: createErrorNotice
3 | prefix: rw|wp_notices|createErrorNotice
4 | description: Returns an action object used in signalling that an error notice is to be created. Refer to createNotice for options documentation.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createerrornotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const { createErrorNotice } = useDispatch( noticesStore );
16 | return (
17 |
19 | createErrorNotice( __( 'An error occurred!' ), {
20 | type: 'snackbar',
21 | explicitDismiss: true,
22 | } )
23 | }
24 | >
25 | { __(
26 | 'Generate an snackbar error notice with explicit dismiss button.'
27 | ) }
28 |
29 | );
30 | }
31 |
--------------------------------------------------------------------------------
/snippet-data/notices/create-info-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: createInfoNotice
3 | prefix: rw|wp_notices|wp_data|createInfoNotice
4 | description: Returns an action object used in signalling that an info notice is to be created. Refer to createNotice for options documentation.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createinfonotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const { createInfoNotice } = useDispatch( noticesStore );
16 | return (
17 |
19 | createInfoNotice( __( 'Something happened!' ), {
20 | isDismissible: false,
21 | } )
22 | }
23 | >
24 | { __( 'Generate a notice that cannot be dismissed.' ) }
25 |
26 | );
27 | };
28 |
--------------------------------------------------------------------------------
/snippet-data/notices/create-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: createNotice
3 | prefix: rw|wp_notices|wp_data|createNotice
4 | description: Returns an action object used in signalling that a notice is to be created.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createnotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const { createNotice } = useDispatch( noticesStore );
16 | return (
17 | createNotice( 'success', __( 'Notice message' ) ) }
19 | >
20 | { __( 'Generate a success notice!' ) }
21 |
22 | );
23 | };
24 |
--------------------------------------------------------------------------------
/snippet-data/notices/create-success-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: createSuccessNotice
3 | prefix: rw|wp_notices|wp_data|createSuccessNotice
4 | description: Returns an action object used in signalling that a success notice is to be created. Refer to createNotice for options documentation.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createsuccessnotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const { createSuccessNotice } = useDispatch( noticesStore );
16 | return (
17 |
19 | createSuccessNotice( __( 'Success!' ), {
20 | type: 'snackbar',
21 | icon: ' ',
22 | } )
23 | }
24 | >
25 | { __( 'Generate a snackbar success notice!' ) }
26 |
27 | );
28 | };
29 |
--------------------------------------------------------------------------------
/snippet-data/notices/create-warning-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: createWarningNotice
3 | prefix: rw|wp_notices|wp_data|createWarningNotice
4 | description: Returns an action object used in signalling that a warning notice is to be created. Refer to createNotice for options documentation.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createwarningnotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const { createWarningNotice, createInfoNotice } =
16 | useDispatch( noticesStore );
17 | return (
18 |
20 | createWarningNotice( __( 'Warning!' ), {
21 | onDismiss: () => {
22 | createInfoNotice(
23 | __( 'The warning has been dismissed!' )
24 | );
25 | },
26 | } )
27 | }
28 | >
29 | { __( 'Generates a warning notice with onDismiss callback' ) }
30 |
31 | );
32 | };
33 |
--------------------------------------------------------------------------------
/snippet-data/notices/get-notices.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: getNotices
3 | prefix: rw|wp_notices|wp_data|getNotices
4 | description: Returns all notices as an array, optionally for a given context. Defaults to the global context.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#getnotices
8 |
9 | import { useSelect } from '@wordpress/data';
10 | import { store as noticesStore } from '@wordpress/notices';
11 |
12 | const ExampleComponent = () => {
13 | const notices = useSelect( ( select ) =>
14 | select( noticesStore ).getNotices()
15 | );
16 | return (
17 |
18 | { notices.map( ( notice ) => (
19 | { notice.content }
20 | ) ) }
21 |
22 | );
23 | };
24 |
--------------------------------------------------------------------------------
/snippet-data/notices/remove-notice.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: removeNotice
3 | prefix: rw|wp_notices|wp_data|removeNotice
4 | description: Returns an action object used in signalling that a notice is to be removed.
5 | ---
6 |
7 | $LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#removenotice
8 |
9 | import { __ } from '@wordpress/i18n';
10 | import { useDispatch } from '@wordpress/data';
11 | import { store as noticesStore } from '@wordpress/notices';
12 | import { Button } from '@wordpress/components';
13 |
14 | const ExampleComponent = () => {
15 | const notices = useSelect( ( select ) =>
16 | select( noticesStore ).getNotices()
17 | );
18 | const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
19 |
20 | return (
21 | <>
22 |
24 | createWarningNotice( __( 'Warning!' ), {
25 | isDismissible: false,
26 | } )
27 | }
28 | >
29 | { __( 'Generate a notice' ) }
30 |
31 | { notices.length > 0 && (
32 | removeNotice( notices[ 0 ].id ) }>
33 | { __( 'Remove the notice' ) }
34 |
35 | ) }
36 | >
37 | );
38 | };
39 |
--------------------------------------------------------------------------------
/snippet-data/php/admin-screen.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Create a new Admin Screen
3 | prefix: rw|screen
4 | description: Register a new admin screen
5 | ---
6 |
7 | /**
8 | * Registers the settings pave
9 | */
10 | function register_plugin_settings_page() {
11 | add_menu_page(
12 | __( '${1:name}' ),
13 | __( '${1:name}' ),
14 | 'manage_options',
15 | '${1:page-slug}',
16 | __NAMESPACE__ . '\render_settings_page',
17 | 'dashicons-yes'
18 | );
19 | }
20 |
21 | add_action( 'admin_menu', __NAMESPACE__ . '\register_plugin_settings_page' );
22 |
23 | /**
24 | * Renders the settings page
25 | */
26 | function render_settings_page() {
27 | ?>
28 |
29 | Page Content
30 |
31 |
26 | Edit
27 |
28 | );
29 | }
30 |
--------------------------------------------------------------------------------
/snippet-data/structure/block-save.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Block Save component
3 | prefix: rw|block|save
4 | description: Create a Save component for custom block development.
5 | ---
6 |
7 | /**
8 | * React hook that is used to mark the block wrapper element.
9 | * It provides all the necessary props like the class name.
10 | *
11 | * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
12 | */
13 | import { useBlockProps } from '@wordpress/block-editor';
14 |
15 | /**
16 | * The save function defines the way in which the different attributes should
17 | * be combined into the final markup, which is then serialized by the block
18 | * editor into `post_content`.
19 | *
20 | * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
21 | *
22 | * @return {WPElement} Element to render.
23 | */
24 | export default function save() {
25 | return (
26 |
27 |
Save
28 |
29 | );
30 | }
31 |
--------------------------------------------------------------------------------
/snippet-data/structure/get-data.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Retrieve from the WordPress datastore
3 | prefix: rw|wp|getEntityRecords|get-data
4 | description: Add getEntityRecords selector with isLoading and invalidateResolution.
5 | ---
6 |
7 | import { useSelect, useDispatch } from '@wordpress/data';
8 |
9 | const { data, isLoading } = useSelect((select) => {
10 | return {
11 | data: select('core').getEntityRecords('${1:entity}', '${2:type}', {${3}}),
12 | isLoading: select('core/data').isResolving('core', 'getEntityRecords', ['${1:entity}', '${2:type}', {${3}}]),
13 | };
14 | });
15 |
16 | const { invalidateResolution } = useDispatch('core/data');
17 |
18 | $LINE_COMMENT Call this function when needed to re-trigger the getEntityRecords call.
19 | const reQuery = () => {
20 | invalidateResolution('core', 'getEntityRecords', ['${1:entity}', '${2:type}', {${3}}]);
21 | };
22 |
--------------------------------------------------------------------------------
/snippet-data/webpack/custom-entry-points.snip:
--------------------------------------------------------------------------------
1 | ---
2 | title: Custom entry points
3 | prefix: rw|webpack|entrypoints
4 | description: Create a webpack config with custom entry points
5 | ---
6 |
7 | $LINE_COMMENT Import the original config from the @wordpress/scripts package.
8 | const defaultConfig = require("@wordpress/scripts/config/webpack.config");
9 |
10 | $LINE_COMMENT Import the helper to find and generate the entry points in the src directory
11 | const { getWebpackEntryPoints } = require("@wordpress/scripts/utils/config");
12 |
13 | $LINE_COMMENT Add any a new entry point by extending the webpack config.
14 | module.exports = {
15 | ...defaultConfig,
16 | entry: {
17 | ...defaultConfig.entry(),
18 | ${1:entry}: "${2:path}"
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/snippets/api.json:
--------------------------------------------------------------------------------
1 | {
2 | "registerBlockVariation": {
3 | "prefix": [
4 | "rw",
5 | "variation"
6 | ],
7 | "description": "Register a block variation",
8 | "body": [
9 | "import { registerBlockVariation } from '@wordpress/blocks';",
10 | "",
11 | "registerBlockVariation( '${1:namespace/blockname}', {",
12 | "\tname: 'paragraph-red',",
13 | "\ttitle: 'Red Paragraph',",
14 | "\tattributes: {",
15 | "\t\ttextColor: 'vivid-red',",
16 | "\t},",
17 | "\tisActive: [ 'textColor' ],",
18 | "\tscope: [ 'inserter', 'blocks' ],",
19 | "} );"
20 | ]
21 | },
22 | "DomReady": {
23 | "prefix": [
24 | "rw",
25 | "domready"
26 | ],
27 | "description": "Setup domReady",
28 | "body": [
29 | "import domReady from '@wordpress/dom-ready';",
30 | "",
31 | "",
32 | "domReady( () => {",
33 | "\t// This code runs after the DOM is loaded.",
34 | "} );"
35 | ]
36 | },
37 | "registerFormatType": {
38 | "prefix": [
39 | "rw",
40 | "format"
41 | ],
42 | "description": "Register a format type",
43 | "body": [
44 | "import { registerFormatType, toggleFormat } from '@wordpress/rich-text';",
45 | "import { RichTextToolbarButton } from '@wordpress/block-editor';",
46 | "",
47 | "const MyCustomButton = ( { isActive, onChange, value } ) => {",
48 | "\treturn (",
49 | "\t\t {",
53 | "\t\t\t\tonChange(",
54 | "\t\t\t\t\ttoggleFormat( value, {",
55 | "\t\t\t\t\t\ttype: 'my-custom-format/sample-output',",
56 | "\t\t\t\t\t} )",
57 | "\t\t\t\t);",
58 | "\t\t\t} }",
59 | "\t\t\tisActive={ isActive }",
60 | "\t\t/>",
61 | "\t);",
62 | "};",
63 | "",
64 | "registerFormatType( '${1:format}', {",
65 | "\ttitle: 'Sample output',",
66 | "\ttagName: '${2:tag}',",
67 | "\tclassName: '${1:class},",
68 | "\tedit: MyCustomButton,",
69 | "} );"
70 | ]
71 | },
72 | "registerPlugin": {
73 | "prefix": [
74 | "rw",
75 | "registerPlugin"
76 | ],
77 | "description": "Register a plugin for slotfill",
78 | "body": [
79 | "import { registerPlugin } from '@wordpress/plugins';",
80 | "import {",
81 | "\tPluginSidebar,",
82 | "\tPluginSidebarMoreMenuItem,",
83 | "\tPluginPrePublishPanel,",
84 | "\tPluginPostStatusInfo,",
85 | "\tPluginPostPublishPanel,",
86 | "\tPluginMoreMenuItem,",
87 | "\tPluginDocumentSettingPanel,",
88 | "\tPluginBlockSettingsMenuItem,",
89 | "} from '@wordpress/editor';",
90 | "import { PanelBody } from '@wordpress/components';",
91 | "",
92 | "registerPlugin( '${1:plugin}', {",
93 | "\trender: () => {},",
94 | "} );"
95 | ]
96 | },
97 | "Command Pallette": {
98 | "prefix": [
99 | "rw",
100 | "command"
101 | ],
102 | "description": "Register a command",
103 | "body": [
104 | "import { store as commandsStore } from '@wordpress/commands';",
105 | "import { dispatch, select } from '@wordpress/data';",
106 | "import { __ } from '@wordpress/i18n';",
107 | "",
108 | "function doWork() {",
109 | "}",
110 | "",
111 | "dispatch( commandsStore ).registerCommand( {",
112 | "\tname: '${1:command name}',",
113 | "\tlabel: __( '${1:label}' ),",
114 | "\tcallback: ( { close } ) => {",
115 | "\t\tdoWork();",
116 | "\t\tclose();",
117 | "\t},",
118 | "} );"
119 | ]
120 | }
121 | }
--------------------------------------------------------------------------------
/snippets/block-editor.json:
--------------------------------------------------------------------------------
1 | {
2 | "InspectorControls": {
3 | "prefix": [
4 | "rw",
5 | "wp_blockEditor",
6 | "InspectorControls"
7 | ],
8 | "description": "Inspector Controls appear in the post settings sidebar when a block is being edited",
9 | "body": [
10 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/block-editor/src/components/inspector-controls",
11 | "",
12 | "import { InspectorControls } from '@wordpress/block-editor';",
13 | "",
14 | "",
15 | "\t$TM_SELECTED_TEXT",
16 | " "
17 | ]
18 | },
19 | "RichText.Content": {
20 | "prefix": [
21 | "rw",
22 | "wp_blockEditor",
23 | "block-editor",
24 | "RichText"
25 | ],
26 | "description": "Inserts a RichText component.",
27 | "body": [
28 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/README.md",
29 | "",
30 | "import { RichText } from '@wordpress/block-editor';",
31 | "",
32 | " "
33 | ]
34 | },
35 | "RichText": {
36 | "prefix": [
37 | "rw",
38 | "wp_blockEditor",
39 | "block-editor",
40 | "RichText"
41 | ],
42 | "description": "Inserts a RichText component.",
43 | "body": [
44 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/README.md",
45 | "",
46 | "import { RichText } from '@wordpress/block-editor';",
47 | "",
48 | " setAttributes( { content } ) }",
51 | "\t${3:tagName=\"${4:div}\"}",
52 | "\t${4:placeholder=\"${5:Placeholder Text\"}",
53 | "\t${6:multiline={${7:boolean|string}}}",
54 | "\t${8:onSplit={(value) => console.log(value)}}",
55 | "\t${9:onReplace]={(blocks) => console.log(blocks)}}",
56 | "\t${10:onMerge]={(forward) => console.log(forward)}}",
57 | "\t${11:onRemove]={(forward) => console.log(forward)}}",
58 | "\t${12:allowedFormats]={[",
59 | "\t\t'core/bold',",
60 | "\t\t'core/code',",
61 | "\t\t'core/image',",
62 | "\t\t'core/italic',",
63 | "\t\t'core/link',",
64 | "\t\t'core/strikethrough',",
65 | "\t\t'core/underline',",
66 | "\t\t'core/text-color',",
67 | "\t\t'core/subscript',",
68 | "\t\t'core/superscript',",
69 | "\t\t'core/keyboard',",
70 | "\t\t]",
71 | "\t}}",
72 | "\t${13:withoutInteractiveFormatting={${14:true|false}}}",
73 | "\t${15:isSelected={${16:true|false}}}",
74 | "\t${17:autocompleters={${18:[]}}}",
75 | "\t${19:preserveWhiteSpace={${20:true|false}}}",
76 | "\t${21:className=\"${22:class-name}\"}",
77 | "/>"
78 | ]
79 | }
80 | }
--------------------------------------------------------------------------------
/snippets/blocks.json:
--------------------------------------------------------------------------------
1 | {
2 | "getCategories": {
3 | "prefix": [
4 | "rw",
5 | "wp_blocks",
6 | "getCategories"
7 | ],
8 | "description": "Returns all the available block categories.",
9 | "body": [
10 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#getcategories",
11 | "",
12 | "import { store as blocksStore } from '@wordpress/blocks';",
13 | "import { useSelect, useDispatch } from '@wordpress/data';",
14 | "",
15 | "const ExampleComponent = () => {",
16 | "\tconst blockCategories = useSelect( ( select ) =>",
17 | "\t\tselect( blocksStore ).getCategories()",
18 | "\t);",
19 | "\tconst { setCategories } = useDispatch( blocksStore );",
20 | "",
21 | "\treturn (",
22 | "\t\t",
24 | "\t\t\t\tsetCategories( [",
25 | "\t\t\t\t\t...blockCategories,",
26 | "\t\t\t\t\t{ title: 'Custom Category', slug: 'custom-category' },",
27 | "\t\t\t\t] )",
28 | "\t\t\t}",
29 | "\t\t>",
30 | "\t\t\t{ __( 'Add a new custom block category' ) }",
31 | "\t\t ",
32 | "\t);",
33 | "};"
34 | ]
35 | },
36 | "setCategories": {
37 | "prefix": [
38 | "rw",
39 | "wp_blocks",
40 | "setCategories"
41 | ],
42 | "description": "Returns an action object used to set block categories.",
43 | "body": [
44 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#setcategories",
45 | "",
46 | "import { store as blocksStore } from '@wordpress/blocks';",
47 | "import { useSelect, useDispatch } from '@wordpress/data';",
48 | "",
49 | "const ExampleComponent = () => {",
50 | "\tconst blockCategories = useSelect( ( select ) =>",
51 | "\t\tselect( blocksStore ).getCategories()",
52 | "\t);",
53 | "\tconst { setCategories } = useDispatch( blocksStore );",
54 | "",
55 | "\treturn (",
56 | "\t\t",
58 | "\t\t\t\tsetCategories( [",
59 | "\t\t\t\t\t...blockCategories,",
60 | "\t\t\t\t\t{ title: 'Custom Category', slug: 'custom-category' },",
61 | "\t\t\t\t] )",
62 | "\t\t\t}",
63 | "\t\t>",
64 | "\t\t\t{ __( 'Add a new custom block category' ) }",
65 | "\t\t ",
66 | "\t);",
67 | "};"
68 | ]
69 | },
70 | "setDefaultBlockName": {
71 | "prefix": [
72 | "rw",
73 | "wp_blocks",
74 | "setDefaultBlockName"
75 | ],
76 | "description": "Returns an action object used to set the default block name.",
77 | "body": [
78 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-blocks/#setdefaultblockname",
79 | "",
80 | "import { store as blocksStore } from '@wordpress/blocks';",
81 | "import { useDispatch } from '@wordpress/data';",
82 | "",
83 | "const ExampleComponent = () => {",
84 | "\tconst { setDefaultBlockName } = useDispatch( blocksStore );",
85 | "",
86 | "\treturn (",
87 | "\t\t setDefaultBlockName( 'core/heading' ) }>",
88 | "\t\t\t{ __( 'Set the default block to Heading' ) }",
89 | "\t\t ",
90 | "\t);",
91 | "};"
92 | ]
93 | }
94 | }
--------------------------------------------------------------------------------
/snippets/components.json:
--------------------------------------------------------------------------------
1 | {
2 | "Alignment Matrix Control": {
3 | "prefix": [
4 | "rw",
5 | "wp_components",
6 | "components",
7 | "AlignmentMatrixControl"
8 | ],
9 | "description": "AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.",
10 | "body": [
11 | "$LINE_COMMENT Reference: https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/alignment-matrix-control\",",
12 | "",
13 | "import { AlignmentMatrixControl } from '@wordpress/components';",
14 | "",
15 | " "
16 | ]
17 | },
18 | "AnglePickerControl": {
19 | "prefix": [
20 | "rw",
21 | "wp_components",
22 | "components",
23 | "AnglePickerControl"
24 | ],
25 | "description": "AnglePickerControl is a React component to render a UI that allows users to pick an angle. Users can choose an angle in a visual UI with the mouse by dragging an angle indicator inside a circle or by directly inserting the desired angle in a text field.",
26 | "body": [
27 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/angle-picker-control",
28 | "",
29 | "import { useState } from '@wordpress/element';",
30 | "import { AnglePickerControl } from '@wordpress/components';",
31 | "",
32 | "const MyAnglePicker = () => {",
33 | "\tconst [ angle, setAngle ] = useState();",
34 | "\treturn ;",
35 | "};"
36 | ]
37 | },
38 | "Animate": {
39 | "prefix": [
40 | "rw",
41 | "wp_components",
42 | "components",
43 | "Animate"
44 | ],
45 | "description": "Simple interface to introduce animations to components.",
46 | "body": [
47 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/animate",
48 | "",
49 | "import { Animate } from '@wordpress/components';",
50 | "",
51 | "const MyAnimatedNotice = () => (",
52 | "\t",
53 | "\t\t{ ( { className } ) => (",
54 | "\t\t\t",
55 | "\t\t\t\tAnimation finished.
",
56 | "\t\t\t ",
57 | "\t\t) }",
58 | "\t ",
59 | ");"
60 | ]
61 | },
62 | "Autocomplete": {
63 | "prefix": [
64 | "rw",
65 | "wp_components",
66 | "components",
67 | "Autocomplete"
68 | ],
69 | "description": "This component is used to provide autocompletion support for a child input component.",
70 | "body": [
71 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/autocomplete",
72 | "",
73 | "import { Autocomplete } from '@wordpress/components';",
74 | "",
75 | "const MyAutocomplete = () => {",
76 | "\tconst autocompleters = [",
77 | "\t\t{",
78 | "\t\t\tname: 'fruit',",
79 | "\t\t\t// The prefix that triggers this completer",
80 | "\t\t\ttriggerprefix: rw|'~',",
81 | "\t\t\t// The option data",
82 | "\t\t\toptions: [",
83 | "\t\t\t\t{ visual: '🍎', name: 'Apple', id: 1 },",
84 | "\t\t\t\t{ visual: '🍊', name: 'Orange', id: 2 },",
85 | "\t\t\t\t{ visual: '🍇', name: 'Grapes', id: 3 },",
86 | "\t\t\t],",
87 | "\t\t\t// Returns a label for an option like \"🍊 Orange\"",
88 | "\t\t\tgetOptionLabel: ( option ) => (",
89 | "\t\t\t\t",
90 | "\t\t\t\t\t{ option.visual } ",
91 | "\t\t\t\t\t{ option.name }",
92 | "\t\t\t\t ",
93 | "\t\t\t),",
94 | "\t\t\t// Declares that options should be matched by their name",
95 | "\t\t\tgetOptionKeywords: ( option ) => [ option.name ],",
96 | "\t\t\t// Declares that the Grapes option is disabled",
97 | "\t\t\tisOptionDisabled: ( option ) => option.name === 'Grapes',",
98 | "\t\t\t// Declares completions should be inserted as abbreviations",
99 | "\t\t\tgetOptionCompletion: ( option ) => (",
100 | "\t\t\t\t{ option.visual } ",
101 | "\t\t\t),",
102 | "\t\t},",
103 | "\t];",
104 | "",
105 | "\treturn (",
106 | "\t\t",
107 | "\t\t\t
",
108 | "\t\t\t\t{ ( { isExpanded, listBoxId, activeId } ) => (",
109 | "\t\t\t\t\t
",
117 | "\t\t\t\t) }",
118 | "\t\t\t ",
119 | "\t\t\t
Type ~ for triggering the autocomplete.
",
120 | "\t\t
",
121 | "\t);",
122 | "};"
123 | ]
124 | },
125 | "BaseControl": {
126 | "prefix": [
127 | "rw",
128 | "wp_components",
129 | "components",
130 | "BaseControl"
131 | ],
132 | "description": "BaseControl component is used to generate labels and help text for components handling user inputs.",
133 | "body": [
134 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/base-control",
135 | "",
136 | "import { BaseControl } from '@wordpress/components';",
137 | "",
138 | "const MyBaseControl = () => (",
139 | "\t",
140 | "\t\t",
141 | "\t ",
142 | ");"
143 | ]
144 | },
145 | "ButtonGroup": {
146 | "prefix": [
147 | "rw",
148 | "wp_components",
149 | "components",
150 | "ButtonGroup"
151 | ],
152 | "description": "ButtonGroup can be used to group any related buttons together. To emphasize related buttons, a group should share a common container.",
153 | "body": [
154 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/button-group",
155 | "",
156 | "import { Button, ButtonGroup } from '@wordpress/components';",
157 | "",
158 | "const MyButtonGroup = () => (",
159 | "\t",
160 | "\t\tButton 1 ",
161 | "\t\tButton 2 ",
162 | "\t ",
163 | ");"
164 | ]
165 | },
166 | "Button": {
167 | "prefix": [
168 | "wp.components",
169 | "components",
170 | "Button"
171 | ],
172 | "description": "Buttons let users take actions and make choices with a single click or tap.",
173 | "body": [
174 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/button",
175 | "",
176 | "import { Button } from '@wordpress/components';",
177 | "",
178 | "const MyButton = () => Click me! ;"
179 | ]
180 | },
181 | "CheckboxControl": {
182 | "prefix": [
183 | "wp.components",
184 | "components",
185 | "CheckboxControl"
186 | ],
187 | "description": "Checkboxes allow the user to select one or more items from a set.",
188 | "body": [
189 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/checkbox-control",
190 | "",
191 | "import { CheckboxControl } from '@wordpress/components';",
192 | "import { useState } from '@wordpress/element';",
193 | "",
194 | "const MyCheckboxControl = () => {",
195 | "\tconst [ isChecked, setChecked ] = useState( true );",
196 | "\treturn (",
197 | "\t\t ",
203 | "\t);",
204 | "};"
205 | ]
206 | },
207 | "ColorIndicator": {
208 | "prefix": [
209 | "wp.components",
210 | "components",
211 | "ColorIndicator"
212 | ],
213 | "description": "Displays a color.",
214 | "body": [
215 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-indicator",
216 | "",
217 | "import { ColorIndicator } from '@wordpress/components';",
218 | "",
219 | "const MyColorIndicator = () => ;"
220 | ]
221 | },
222 | "ColorPalette": {
223 | "prefix": [
224 | "wp.components",
225 | "components",
226 | "ColorPalette"
227 | ],
228 | "description": "Display a color palette",
229 | "body": [
230 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-palette",
231 | "",
232 | "import { ColorPalette } from '@wordpress/components';",
233 | "import { useState } from '@wordpress/element';",
234 | "",
235 | "const MyColorPalette = () => {",
236 | "\tconst [ color, setColor ] = useState ( '#f00' )",
237 | "\tconst colors = [",
238 | "\t\t{ name: 'red', color: '#f00' },",
239 | "\t\t{ name: 'white', color: '#fff' },",
240 | "\t\t{ name: 'blue', color: '#00f' },",
241 | "\t];",
242 | "",
243 | "\treturn (",
244 | "\t\t setColor( color ) }",
248 | "\t\t/>",
249 | "\t);",
250 | "} );"
251 | ]
252 | },
253 | "ColorPicker": {
254 | "prefix": [
255 | "wp.components",
256 | "components",
257 | "ColorPicker"
258 | ],
259 | "description": "ColorPicker is a color picking component based on react-colorful. It lets you pick a color visually or by manipulating the individual RGB(A), HSL(A) and Hex(8) color values.",
260 | "body": [
261 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/color-picker",
262 | "",
263 | "import { ColorPicker } from '@wordpress/components/ui';",
264 | "",
265 | "function Example() {",
266 | "\tconst [color, setColor] = useState();",
267 | "\treturn (",
268 | "\t\t ",
274 | "\t);",
275 | "}"
276 | ]
277 | },
278 | "ComboboxControl": {
279 | "prefix": [
280 | "wp.components",
281 | "components",
282 | "ComboboxControl"
283 | ],
284 | "description": "ComboboxControl is an enhanced version of a SelectControl, with the addition of being able to search for options using a search input.",
285 | "body": [
286 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/combobox-control",
287 | "",
288 | "/**",
289 | " * WordPress dependencies",
290 | " */",
291 | "import { ComboboxControl } from '@wordpress/components';",
292 | "import { useState } from '@wordpress/compose';",
293 | "",
294 | "const options = [",
295 | "\t{",
296 | "\t\tvalue: 'small',",
297 | "\t\tlabel: 'Small',",
298 | "\t},",
299 | "\t{",
300 | "\t\tvalue: 'normal',",
301 | "\t\tlabel: 'Normal',",
302 | "\t},",
303 | "\t{",
304 | "\t\tvalue: 'large',",
305 | "\t\tlabel: 'Large',",
306 | "\t},",
307 | "\t{",
308 | "\t\tvalue: 'huge',",
309 | "\t\tlabel: 'Huge',",
310 | "\t},",
311 | "];",
312 | "",
313 | "function MyComboboxControl() {",
314 | "\tconst [ fontSize, setFontSize ] = useState();",
315 | "\tconst [ filteredOptions, setFilteredOptions ] = useState( options );",
316 | "\treturn (",
317 | "\t\t",
323 | "\t\t\t\tsetFilteredOptions(",
324 | "\t\t\t\t\toptions.filter( ( option ) =>",
325 | "\t\t\t\t\t\toption.label",
326 | "\t\t\t\t\t\t\t.toLowerCase()",
327 | "\t\t\t\t\t\t\t.startsWith( inputValue.toLowerCase() )",
328 | "\t\t\t\t\t)",
329 | "\t\t\t\t)",
330 | "\t\t\t}",
331 | "\t\t/>",
332 | "\t);",
333 | "}"
334 | ]
335 | },
336 | "CustomSelectControl": {
337 | "prefix": [
338 | "wp.components",
339 | "components",
340 | "CustomSelectControl"
341 | ],
342 | "description": "CustomSelectControl allows users to select an item from a single-option menu just like SelectControl, with the addition of being able to provide custom styles for each item in the menu. This means it does not use a native , so should only be used if the custom styling is necessary.",
343 | "body": [
344 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/custom-select-control",
345 | "",
346 | "/**",
347 | " * WordPress dependencies",
348 | " */",
349 | "import { CustomSelectControl } from '@wordpress/components';",
350 | "import { useState } from '@wordpress/element';",
351 | "",
352 | "const options = [",
353 | "\t{",
354 | "\t\tkey: 'small',",
355 | "\t\tname: 'Small',",
356 | "\t\tstyle: { fontSize: '50%' },",
357 | "\t},",
358 | "\t{",
359 | "\t\tkey: 'normal',",
360 | "\t\tname: 'Normal',",
361 | "\t\tstyle: { fontSize: '100%' },",
362 | "\t},",
363 | "\t{",
364 | "\t\tkey: 'large',",
365 | "\t\tname: 'Large',",
366 | "\t\tstyle: { fontSize: '200%' },",
367 | "\t},",
368 | "\t{",
369 | "\t\tkey: 'huge',",
370 | "\t\tname: 'Huge',",
371 | "\t\tstyle: { fontSize: '300%' },",
372 | "\t},",
373 | "];",
374 | "",
375 | "function MyCustomSelectControl() {",
376 | "\tconst [ , setFontSize ] = useState();",
377 | "\treturn (",
378 | "\t\t setFontSize( selectedItem ) }",
382 | "\t\t/>",
383 | "\t);",
384 | "}",
385 | "",
386 | "function MyControlledCustomSelectControl() {",
387 | "\tconst [ fontSize, setFontSize ] = useState( options[ 0 ] );",
388 | "\treturn (",
389 | "\t\t setFontSize( selectedItem ) }",
393 | "\t\t\tvalue={ options.find( ( option ) => option.key === fontSize.key ) }",
394 | "\t\t/>",
395 | "\t);",
396 | "}"
397 | ]
398 | },
399 | "Dashicon": {
400 | "prefix": [
401 | "wp.components",
402 | "components",
403 | "Dashicon"
404 | ],
405 | "description": "add description",
406 | "body": [
407 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dashicon",
408 | "",
409 | "import { Dashicon } from '@wordpress/components';",
410 | "",
411 | "const MyDashicon = () => (",
412 | "\t",
413 | "\t\t ",
414 | "\t\t ",
415 | "\t\t ",
416 | "\t
",
417 | ");"
418 | ]
419 | },
420 | "DateTimePicker": {
421 | "prefix": [
422 | "wp.components",
423 | "components",
424 | "DateTimePicker"
425 | ],
426 | "description": "DateTimePicker is a React component that renders a calendar and clock for date and time selection. The calendar and clock components can be accessed individually using the DatePicker and TimePicker components respectively.",
427 | "body": [
428 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/date-time",
429 | "",
430 | "import { DateTimePicker } from '@wordpress/components';",
431 | "import { useState } from '@wordpress/element';",
432 | "",
433 | "const MyDateTimePicker = () => {",
434 | "\tconst [ date, setDate ] = useState( new Date() );",
435 | "",
436 | "\treturn (",
437 | "\t\t setDate( newDate ) }",
440 | "\t\t\tis12Hour={ true }",
441 | "\t\t/>",
442 | "\t);",
443 | "}"
444 | ]
445 | },
446 | "Disabled": {
447 | "prefix": [
448 | "wp.components",
449 | "components",
450 | "Disabled"
451 | ],
452 | "description": "Disabled is a component which disables descendant tabbable elements and prevents pointer interaction.",
453 | "body": [
454 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/disabled",
455 | "",
456 | "import { Button, Disabled, TextControl } from '@wordpress/components';",
457 | "import { useState } from '@wordpress/element';",
458 | "",
459 | "const MyDisabled = () => {",
460 | "\tconst [ isDisabled, setIsDisabled ] = useState( true );",
461 | "",
462 | "\tlet input = {} } />;",
463 | "\tif ( isDisabled ) {",
464 | "\t\tinput = { input } ;",
465 | "\t}",
466 | "",
467 | "\tconst toggleDisabled = () => {",
468 | "\t\tsetIsDisabled( ( state ) => ! state );",
469 | "\t};",
470 | "",
471 | "\treturn (",
472 | "\t\t",
473 | "\t\t\t{ input }",
474 | "\t\t\t",
475 | "\t\t\t\tToggle Disabled",
476 | "\t\t\t ",
477 | "\t\t
",
478 | "\t);",
479 | "};"
480 | ]
481 | },
482 | "Draggable": {
483 | "prefix": [
484 | "wp.components",
485 | "components",
486 | "Draggable"
487 | ],
488 | "description": "Draggable is a Component that provides a way to set up a a cross-browser (including IE) customisable drag image and the transfer data for the drag event. It decouples the drag handle and the element to drag. Use it by wrapping the component that will become the drag handle and providing the DOM ID of the element to drag.",
489 | "body": [
490 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/draggable",
491 | "",
492 | "import { Draggable, Panel, PanelBody } from '@wordpress/components';",
493 | "import { Icon, more } from '@wordpress/icons';",
494 | "",
495 | "const MyDraggable = () => (",
496 | "\t",
497 | "\t\t
",
498 | "\t\t\t",
499 | "\t\t\t\t",
500 | "\t\t\t\t\t{ ( { onDraggableStart, onDraggableEnd } ) => (",
501 | "\t\t\t\t\t\t",
507 | "\t\t\t\t\t\t\t ",
508 | "\t\t\t\t\t\t
",
509 | "\t\t\t\t\t) }",
510 | "\t\t\t\t ",
511 | "\t\t\t ",
512 | "\t\t ",
513 | "\t
",
514 | ");"
515 | ]
516 | },
517 | "DropdownMenu": {
518 | "prefix": [
519 | "wp.components",
520 | "components",
521 | "DropdownMenu"
522 | ],
523 | "description": "The DropdownMenu displays a list of actions (each contained in a MenuItem, MenuItemsChoice, or MenuGroup) in a compact way. It appears in a Popover after the user has interacted with an element (a button or icon) or when they perform a specific action.",
524 | "body": [
525 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dropdown-menu",
526 | "",
527 | "import { DropdownMenu } from '@wordpress/components';",
528 | "import {",
529 | "\tmore,",
530 | "\tarrowLeft,",
531 | "\tarrowRight,",
532 | "\tarrowUp,",
533 | "\tarrowDown,",
534 | "} from '@wordpress/icons';",
535 | "",
536 | "const MyDropdownMenu = () => (",
537 | "\t console.log( 'up' ),",
545 | "\t\t\t},",
546 | "\t\t\t{",
547 | "\t\t\t\ttitle: 'Right',",
548 | "\t\t\t\ticon: arrowRight,",
549 | "\t\t\t\tonClick: () => console.log( 'right' ),",
550 | "\t\t\t},",
551 | "\t\t\t{",
552 | "\t\t\t\ttitle: 'Down',",
553 | "\t\t\t\ticon: arrowDown,",
554 | "\t\t\t\tonClick: () => console.log( 'down' ),",
555 | "\t\t\t},",
556 | "\t\t\t{",
557 | "\t\t\t\ttitle: 'Left',",
558 | "\t\t\t\ticon: arrowLeft,",
559 | "\t\t\t\tonClick: () => console.log( 'left' ),",
560 | "\t\t\t},",
561 | "\t\t] }",
562 | "\t/>",
563 | ");"
564 | ]
565 | },
566 | "Dropdown": {
567 | "prefix": [
568 | "wp.components",
569 | "components",
570 | "Dropdown"
571 | ],
572 | "description": "Dropdown is a React component to render a button that opens a floating content modal when clicked.",
573 | "body": [
574 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/dropdown",
575 | "",
576 | "import { Button, Dropdown } from '@wordpress/components';",
577 | "",
578 | "const MyDropdown = () => (",
579 | "\t (",
584 | "\t\t\t",
589 | "\t\t\t\tToggle Popover!",
590 | "\t\t\t ",
591 | "\t\t) }",
592 | "\t\trenderContent={ () => This is the content of the popover.
}",
593 | "\t/>",
594 | ");"
595 | ]
596 | },
597 | "Dropzone": {
598 | "prefix": [
599 | "wp.components",
600 | "components",
601 | "Dropzone"
602 | ],
603 | "description": "DropZone is a Component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.",
604 | "body": [
605 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/drop-zone",
606 | "",
607 | "import { DropZone } from '@wordpress/components';",
608 | "import { useState } from '@wordpress/element';",
609 | "",
610 | "const MyDropZone = () => {",
611 | "\tconst [ hasDropped, setHasDropped ] = useState( false );",
612 | "",
613 | "\treturn (",
614 | "\t\t",
615 | "\t\t\t{ hasDropped ? 'Dropped!' : 'Drop something here' }",
616 | "\t\t\t setHasDropped( true ) }",
618 | "\t\t\t\tonHTMLDrop={ () => setHasDropped( true ) }",
619 | "\t\t\t\tonDrop={ () => setHasDropped( true ) }",
620 | "\t\t\t/>",
621 | "\t\t
",
622 | "\t);",
623 | "}"
624 | ]
625 | },
626 | "DuotonePicker & DuotoneSwatch": {
627 | "prefix": [
628 | "wp.components",
629 | "components",
630 | "DuotonePicker",
631 | "DuotoneSwatch"
632 | ],
633 | "description": "add description",
634 | "body": [
635 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/duotone-picker",
636 | "",
637 | "import { DuotonePicker, DuotoneSwatch } from '@wordpress/components';",
638 | "import { useState } from '@wordpress/element';",
639 | "",
640 | "const DUOTONE_PALETTE = [",
641 | "\t{ colors: [ '#8c00b7', '#fcff41' ], name: 'Purple and yellow', slug: 'purple-yellow' },",
642 | "\t{ colors: [ '#000097', '#ff4747' ], name: 'Blue and red', slug: 'blue-red' },",
643 | "];",
644 | "",
645 | "const COLOR_PALETTE = [",
646 | "\t{ color: '#ff4747', name: 'Red', slug: 'red' },",
647 | "\t{ color: '#fcff41', name: 'Yellow', slug: 'yellow' },",
648 | "\t{ color: '#000097', name: 'Blue', slug: 'blue' },",
649 | "\t{ color: '#8c00b7', name: 'Purple', slug: 'purple' },",
650 | "];",
651 | "",
652 | "const Example = () => {",
653 | "\tconst [ duotone, setDuotone ] = useState( [ '#000000', '#ffffff' ] );",
654 | "\treturn (",
655 | "\t\t<>",
656 | "\t\t\t ",
662 | "\t\t\t ",
663 | "\t\t>",
664 | "\t);",
665 | "};",
666 | "`"
667 | ]
668 | },
669 | "ExternalLink": {
670 | "prefix": [
671 | "wp.components",
672 | "components",
673 | "ExternalLink"
674 | ],
675 | "description": "add description",
676 | "body": [
677 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/external-link",
678 | "",
679 | "import { ExternalLink } from '@wordpress/components';",
680 | "",
681 | "const MyExternalLink = () => (",
682 | "\tWordPress.org ",
683 | ");"
684 | ]
685 | },
686 | "FocalPointPicker": {
687 | "prefix": [
688 | "wp.components",
689 | "components",
690 | "FocalPointPicker"
691 | ],
692 | "description": "Focal Point Picker is a component which creates a UI for identifying the most important visual point of an image.",
693 | "body": [
694 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/focal-point-picker",
695 | "",
696 | "import { FocalPointPicker } from '@wordpress/components';",
697 | "import { useState } from '@wordpress/element';",
698 | "",
699 | "const Example = () => {",
700 | "\tconst [ focalPoint, setFocalPoint ] = useState( {",
701 | "\t\tx: 0.5,",
702 | "\t\ty: 0.5,",
703 | "\t} );",
704 | "",
705 | "\tconst url = '/path/to/image';",
706 | "\tconst dimensions = {",
707 | "\t\twidth: 400,",
708 | "\t\theight: 100,",
709 | "\t};",
710 | "",
711 | "\t/* Example function to render the CSS styles based on Focal Point Picker value */",
712 | "\tconst style = {",
713 | "\t\tbackgroundImage: `url(${ url })`,",
714 | "\t\tbackgroundPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`,",
715 | "\t};",
716 | "",
717 | "\treturn (",
718 | "\t\t<>",
719 | "\t\t\t setFocalPoint( { focalPoint } ) }",
724 | "\t\t\t/>",
725 | "\t\t\t
",
726 | "\t\t>",
727 | "\t);",
728 | "};"
729 | ]
730 | },
731 | "FontSizePicker": {
732 | "prefix": [
733 | "wp.components",
734 | "components",
735 | "FontSizePicker"
736 | ],
737 | "description": "FontSizePicker is a React component that renders a UI that allows users to select a font size",
738 | "body": [
739 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/font-size-picker",
740 | "",
741 | "import { FontSizePicker } from '@wordpress/components';",
742 | "import { useState } from '@wordpress/element';",
743 | "import { __ } from '@wordpress/i18n';",
744 | "",
745 | "const fontSizes = [",
746 | "\t{",
747 | "\t\tname: __( 'Small' ),",
748 | "\t\tslug: 'small',",
749 | "\t\tsize: 12,",
750 | "\t},",
751 | "\t{",
752 | "\t\tname: __( 'Big' ),",
753 | "\t\tslug: 'big',",
754 | "\t\tsize: 26,",
755 | "\t},",
756 | "];",
757 | "const fallbackFontSize = 16;",
758 | "",
759 | "const MyFontSizePicker = () => {",
760 | "\tconst [ fontSize, setFontSize ] = useState( 12 );",
761 | "",
762 | "\treturn (",
763 | "\t\t {",
768 | "\t\t\t\tsetFontSize( newFontSize );",
769 | "\t\t\t} }",
770 | "\t\t/>",
771 | "\t);",
772 | "};",
773 | "",
774 | "...",
775 | "",
776 | " "
777 | ]
778 | },
779 | "FormFileUpload": {
780 | "prefix": [
781 | "wp.components",
782 | "components",
783 | "FormFileUpload"
784 | ],
785 | "description": "Renders a FormFileUpload",
786 | "body": [
787 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-file-upload",
788 | "",
789 | "import { FormFileUpload } from '@wordpress/components';",
790 | "",
791 | "const MyFormFileUpload = () => (",
792 | "\t console.log( 'new image' ) }",
795 | "\t>",
796 | "\t\tUpload",
797 | "\t ",
798 | ");"
799 | ]
800 | },
801 | "FormToggle": {
802 | "prefix": [
803 | "wp.components",
804 | "components",
805 | "FormToggle"
806 | ],
807 | "description": "Renders a FormToggle",
808 | "body": [
809 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-toggle",
810 | "",
811 | "import { FormToggle } from '@wordpress/components';",
812 | "import { useState } from '@wordpress/element';",
813 | "",
814 | "const MyFormToggle = () => {",
815 | "\tconst [ isChecked, setChecked ] = useState( true );",
816 | "",
817 | "\t setChecked( ( state ) => ! state ) }",
820 | "\t/>",
821 | "};"
822 | ]
823 | },
824 | "FormTokenField": {
825 | "prefix": [
826 | "wp.components",
827 | "components",
828 | "FormTokenField"
829 | ],
830 | "description": "A FormTokenField is a field similar to the tags and categories fields in the interim editor chrome, or the \"to\" field in Mail on OS X. Tokens can be entered by typing them or selecting them from a list of suggested tokens.",
831 | "body": [
832 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/form-token-field",
833 | "",
834 | "import { FormTokenField } from '@wordpress/components';",
835 | "import { useState } from '@wordpress/element';",
836 | "",
837 | "const continents = [",
838 | "\t'Africa',",
839 | "\t'America',",
840 | "\t'Antarctica',",
841 | "\t'Asia',",
842 | "\t'Europe',",
843 | "\t'Oceania',",
844 | "];",
845 | "",
846 | "const MyFormTokenField = () => {",
847 | "\tconst [ selectedContinents, setSelectedContinents ] = useState( [] );",
848 | "",
849 | "\treturn(",
850 | "\t\t setSelectedContinents( tokens ) }",
854 | "\t\t/>",
855 | "\t);",
856 | "};"
857 | ]
858 | },
859 | "Guide": {
860 | "prefix": [
861 | "wp.components",
862 | "components",
863 | "Guide"
864 | ],
865 | "description": "Guide is a React component that renders a user guide in a modal.",
866 | "body": [
867 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/guide",
868 | "",
869 | "function MyTutorial() {",
870 | "\tconst [ isOpen, setIsOpen ] = useState( true );",
871 | "",
872 | "\tif ( ! isOpen ) {",
873 | "\t\treturn null;",
874 | "\t}",
875 | "",
876 | "\treturn (",
877 | "\t\t setIsOpen( false ) }",
879 | "\t\t\tpages={ [",
880 | "\t\t\t\t{",
881 | "\t\t\t\t\tcontent: Welcome to the ACME Store!
,",
882 | "\t\t\t\t},",
883 | "\t\t\t\t{",
884 | "\t\t\t\t\timage: ,",
885 | "\t\t\t\t\tcontent: (",
886 | "\t\t\t\t\t\t",
887 | "\t\t\t\t\t\t\tClick Add to Cart to buy a product.",
888 | "\t\t\t\t\t\t
",
889 | "\t\t\t\t\t),",
890 | "\t\t\t\t},",
891 | "\t\t\t] }",
892 | "\t\t/>",
893 | "\t);",
894 | "}"
895 | ]
896 | },
897 | "PanelBody": {
898 | "prefix": [
899 | "rw",
900 | "wp_components",
901 | "PanelBody"
902 | ],
903 | "description": "The PanelBody creates a collapsible container that can be toggled open or closed.",
904 | "body": [
905 | "import { PanelBody} from '@wordpress/components';",
906 | "",
907 | "$LINE_COMMENT @see https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/panel#panelbody",
908 | "",
909 | " {console.log('Toggled');}}}",
915 | "\t${9:initialOpen={${10:true|false}}}",
916 | "\t${11:children={(opened) => {console.log(opened);}}}",
917 | "\t${12:buttonProps={${13:{}}}}",
918 | "\t>",
919 | "\t\t$TM_SELECTED_TEXT",
920 | " "
921 | ]
922 | }
923 | }
--------------------------------------------------------------------------------
/snippets/core-data.json:
--------------------------------------------------------------------------------
1 | {
2 | "getCurrentUser": {
3 | "prefix": [
4 | "rw",
5 | "wp_coreData",
6 | "getCurrentUser"
7 | ],
8 | "description": "Returns the current user",
9 | "body": [
10 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core/#getcurrentuser",
11 | "",
12 | "import { store as coreDataStore } from '@wordpress/core-data';",
13 | "import { useSelect } from '@wordpress/data';",
14 | "import { sprintf, __ } from '@wordpress/i18n';",
15 | "",
16 | "const ExampleComponent = () => {",
17 | "\tconst currentUser = useSelect( ( select ) =>",
18 | "\t\tselect( coreDataStore ).getCurrentUser()",
19 | "\t);",
20 | "",
21 | "\treturn currentUser ? (",
22 | "\t\t{ sprintf( __( 'Hello, %s!' ), currentUser.name ) }
",
23 | "\t\t) : (",
24 | "\t\t{ __( 'Loading User information…' ) }
",
25 | "\t);",
26 | " };"
27 | ]
28 | }
29 | }
--------------------------------------------------------------------------------
/snippets/data.json:
--------------------------------------------------------------------------------
1 | {
2 | "getEmbedPreview": {
3 | "prefix": [
4 | "rw",
5 | "wp_data",
6 | "getEmbedPreview"
7 | ],
8 | "description": "add description",
9 | "body": [
10 | "$LINE_COMMENT @see reference-link",
11 | "import { store as coreDataStore } from '@wordpress/core-data';",
12 | "import { useSelect } from '@wordpress/data';",
13 | "",
14 | "const embedPreview = useSelect( ( select ) =>",
15 | "\tselect( coreDataStore ).getEmbedPreview( {$1} )",
16 | ");"
17 | ]
18 | }
19 | }
--------------------------------------------------------------------------------
/snippets/js.json:
--------------------------------------------------------------------------------
1 | {
2 | "requestAnimationFrame": {
3 | "prefix": [
4 | "rw",
5 | "animate"
6 | ],
7 | "description": "requestAnimationFrame",
8 | "body": [
9 | "function loop() {",
10 | "\t// Work to be done each loop.",
11 | "",
12 | "\t// Update this to be a real condition",
13 | "\tif ( true ) {",
14 | "\t\trequestAnimationFrame( showTime );",
15 | "\t}",
16 | "}",
17 | "",
18 | "// kick it all off",
19 | "requestAnimationFrame( loop );"
20 | ]
21 | }
22 | }
--------------------------------------------------------------------------------
/snippets/json.json:
--------------------------------------------------------------------------------
1 | {
2 | "Generate block.json file": {
3 | "prefix": [
4 | "rw",
5 | "wp",
6 | "json",
7 | "block"
8 | ],
9 | "description": "Generates the contents of a block.json file",
10 | "body": [
11 | "{",
12 | " \"apiVersion\": 2,",
13 | " \"name\": \"${1:example-name}\",",
14 | " \"title\": \"${2:Title}\",",
15 | " \"category\": \"${3:common}\",",
16 | " \"description\": \"${4:Description}\",",
17 | " \"text-domain\": \"${5:example-text-domain}\",",
18 | " \"icon\": \"${6:feedback}\",",
19 | " \"attributes\": {},",
20 | " \"keywords\": [],",
21 | " \"version\": \"${7:0.0.1}\",",
22 | " \"providesContext\": {},",
23 | " \"usesContext\": [],",
24 | " \"styles\": [],",
25 | " \"example\": {",
26 | " \"attributes\": {}",
27 | " },",
28 | " \"supports\": {},",
29 | " \"editorScript\": \"${8:file:./build/index.js}\",",
30 | " \"script\": \"${9:file:./build/script.js}\",",
31 | " \"editorStyle\": \"${10:file:./build/index.css}\",",
32 | " \"style\": \"${11:file:./build/index.css}\",",
33 | "\t\"viewScript\" : \"${12:file:./build/view.js}\",",
34 | "\t\"render\" : \"${13:file:./build/template.php}\"",
35 | "}"
36 | ]
37 | },
38 | "Generate a basic theme.json file": {
39 | "prefix": [
40 | "rw",
41 | "wp",
42 | "json",
43 | "theme"
44 | ],
45 | "description": "Generates the contents of a theme.json file",
46 | "body": [
47 | "{",
48 | "\t\"$schema\": \"http://schemas.wp.org/trunk/theme.json\",",
49 | "\t\"version\": 2,",
50 | "\t\"settings\": {",
51 | "\t\t\"layout\": {",
52 | "\t\t\t\"contentSize\": \"${1:650px}\",",
53 | "\t\t\t\"wideSize\": \"${2:1000px}\"",
54 | "\t\t}",
55 | "\t}",
56 | "}"
57 | ]
58 | }
59 | }
--------------------------------------------------------------------------------
/snippets/notices.json:
--------------------------------------------------------------------------------
1 | {
2 | "createErrorNotice": {
3 | "prefix": [
4 | "rw",
5 | "wp_notices",
6 | "createErrorNotice"
7 | ],
8 | "description": "Returns an action object used in signalling that an error notice is to be created. Refer to createNotice for options documentation.",
9 | "body": [
10 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createerrornotice",
11 | "",
12 | "import { __ } from '@wordpress/i18n';",
13 | "import { useDispatch } from '@wordpress/data';",
14 | "import { store as noticesStore } from '@wordpress/notices';",
15 | "import { Button } from '@wordpress/components';",
16 | "",
17 | "const ExampleComponent = () => {",
18 | " const { createErrorNotice } = useDispatch( noticesStore );",
19 | " return (",
20 | " ",
22 | " createErrorNotice( __( 'An error occurred!' ), {",
23 | " type: 'snackbar',",
24 | " explicitDismiss: true,",
25 | " } )",
26 | " }",
27 | " >",
28 | " { __(",
29 | " 'Generate an snackbar error notice with explicit dismiss button.'",
30 | " ) }",
31 | " ",
32 | " );",
33 | "}"
34 | ]
35 | },
36 | "createInfoNotice": {
37 | "prefix": [
38 | "rw",
39 | "wp_notices",
40 | "wp_data",
41 | "createInfoNotice"
42 | ],
43 | "description": "Returns an action object used in signalling that an info notice is to be created. Refer to createNotice for options documentation.",
44 | "body": [
45 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createinfonotice",
46 | "",
47 | "import { __ } from '@wordpress/i18n';",
48 | "import { useDispatch } from '@wordpress/data';",
49 | "import { store as noticesStore } from '@wordpress/notices';",
50 | "import { Button } from '@wordpress/components';",
51 | "",
52 | "const ExampleComponent = () => {",
53 | " const { createInfoNotice } = useDispatch( noticesStore );",
54 | " return (",
55 | " ",
57 | " createInfoNotice( __( 'Something happened!' ), {",
58 | " isDismissible: false,",
59 | " } )",
60 | " }",
61 | " >",
62 | " { __( 'Generate a notice that cannot be dismissed.' ) }",
63 | " ",
64 | " );",
65 | "};"
66 | ]
67 | },
68 | "createNotice": {
69 | "prefix": [
70 | "rw",
71 | "wp_notices",
72 | "wp_data",
73 | "createNotice"
74 | ],
75 | "description": "Returns an action object used in signalling that a notice is to be created.",
76 | "body": [
77 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createnotice",
78 | "",
79 | "import { __ } from '@wordpress/i18n';",
80 | "import { useDispatch } from '@wordpress/data';",
81 | "import { store as noticesStore } from '@wordpress/notices';",
82 | "import { Button } from '@wordpress/components';",
83 | "",
84 | "const ExampleComponent = () => {",
85 | " const { createNotice } = useDispatch( noticesStore );",
86 | " return (",
87 | " createNotice( 'success', __( 'Notice message' ) ) }",
89 | " >",
90 | " { __( 'Generate a success notice!' ) }",
91 | " ",
92 | " );",
93 | "};"
94 | ]
95 | },
96 | "createSuccessNotice": {
97 | "prefix": [
98 | "rw",
99 | "wp_notices",
100 | "wp_data",
101 | "createSuccessNotice"
102 | ],
103 | "description": "Returns an action object used in signalling that a success notice is to be created. Refer to createNotice for options documentation.",
104 | "body": [
105 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createsuccessnotice",
106 | "",
107 | "import { __ } from '@wordpress/i18n';",
108 | "import { useDispatch } from '@wordpress/data';",
109 | "import { store as noticesStore } from '@wordpress/notices';",
110 | "import { Button } from '@wordpress/components';",
111 | "",
112 | "const ExampleComponent = () => {",
113 | " const { createSuccessNotice } = useDispatch( noticesStore );",
114 | " return (",
115 | " ",
117 | " createSuccessNotice( __( 'Success!' ), {",
118 | " type: 'snackbar',",
119 | " icon: ' ',",
120 | " } )",
121 | " }",
122 | " >",
123 | " { __( 'Generate a snackbar success notice!' ) }",
124 | " ",
125 | " );",
126 | "};"
127 | ]
128 | },
129 | "createWarningNotice": {
130 | "prefix": [
131 | "rw",
132 | "wp_notices",
133 | "wp_data",
134 | "createWarningNotice"
135 | ],
136 | "description": "Returns an action object used in signalling that a warning notice is to be created. Refer to createNotice for options documentation.",
137 | "body": [
138 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createwarningnotice",
139 | "",
140 | "import { __ } from '@wordpress/i18n';",
141 | "import { useDispatch } from '@wordpress/data';",
142 | "import { store as noticesStore } from '@wordpress/notices';",
143 | "import { Button } from '@wordpress/components';",
144 | "",
145 | "const ExampleComponent = () => {",
146 | " const { createWarningNotice, createInfoNotice } =",
147 | " useDispatch( noticesStore );",
148 | " return (",
149 | " ",
151 | " createWarningNotice( __( 'Warning!' ), {",
152 | " onDismiss: () => {",
153 | " createInfoNotice(",
154 | " __( 'The warning has been dismissed!' )",
155 | " );",
156 | " },",
157 | " } )",
158 | " }",
159 | " >",
160 | " { __( 'Generates a warning notice with onDismiss callback' ) }",
161 | " ",
162 | " );",
163 | "};"
164 | ]
165 | },
166 | "getNotices": {
167 | "prefix": [
168 | "rw",
169 | "wp_notices",
170 | "wp_data",
171 | "getNotices"
172 | ],
173 | "description": "Returns all notices as an array, optionally for a given context. Defaults to the global context.",
174 | "body": [
175 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#getnotices",
176 | "",
177 | "import { useSelect } from '@wordpress/data';",
178 | "import { store as noticesStore } from '@wordpress/notices';",
179 | "",
180 | "const ExampleComponent = () => {",
181 | " const notices = useSelect( ( select ) =>",
182 | " select( noticesStore ).getNotices()",
183 | " );",
184 | " return (",
185 | " ",
186 | " { notices.map( ( notice ) => (",
187 | " { notice.content } ",
188 | " ) ) }",
189 | " ",
190 | " );",
191 | "};"
192 | ]
193 | },
194 | "removeNotice": {
195 | "prefix": [
196 | "rw",
197 | "wp_notices",
198 | "wp_data",
199 | "removeNotice"
200 | ],
201 | "description": "Returns an action object used in signalling that a notice is to be removed.",
202 | "body": [
203 | "$LINE_COMMENT @see https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#removenotice",
204 | "",
205 | "import { __ } from '@wordpress/i18n';",
206 | "import { useDispatch } from '@wordpress/data';",
207 | "import { store as noticesStore } from '@wordpress/notices';",
208 | "import { Button } from '@wordpress/components';",
209 | "",
210 | "const ExampleComponent = () => {",
211 | " const notices = useSelect( ( select ) =>",
212 | " select( noticesStore ).getNotices()",
213 | " );",
214 | " const { createWarningNotice, removeNotice } = useDispatch( noticesStore );",
215 | "",
216 | " return (",
217 | " <>",
218 | " ",
220 | " createWarningNotice( __( 'Warning!' ), {",
221 | " isDismissible: false,",
222 | " } )",
223 | " }",
224 | " >",
225 | " { __( 'Generate a notice' ) }",
226 | " ",
227 | " { notices.length > 0 && (",
228 | " removeNotice( notices[ 0 ].id ) }>",
229 | " { __( 'Remove the notice' ) }",
230 | " ",
231 | " ) }",
232 | " >",
233 | " );",
234 | "};"
235 | ]
236 | }
237 | }
--------------------------------------------------------------------------------
/snippets/php.json:
--------------------------------------------------------------------------------
1 | {
2 | "Admin Screen": {
3 | "prefix": [
4 | "rw",
5 | "screen"
6 | ],
7 | "description": "Register a new admin screen",
8 | "body": [
9 | "/**",
10 | " * Registers the settings pave",
11 | " */",
12 | "function register_plugin_settings_page() {",
13 | "\tadd_menu_page(",
14 | "\t\t__( '${1:name}' ),",
15 | "\t\t__( '${1:name}' ),",
16 | "\t\t'manage_options',",
17 | "\t\t'${1:page-slug}',",
18 | "\t\t__NAMESPACE__ . '\\render_settings_page',",
19 | "\t\t'dashicons-yes'",
20 | "\t);",
21 | "}",
22 | "",
23 | "add_action( 'admin_menu', __NAMESPACE__ . '\\register_plugin_settings_page' );",
24 | "",
25 | "/**",
26 | " * Renders the settings page",
27 | " */",
28 | "function render_settings_page() {",
29 | "\t?>",
30 | "\t",
31 | "\t\tPage Content",
32 | "\t
",
33 | "\t",
29 | "\t\t\tEdit
",
30 | "\t\t",
31 | "\t);",
32 | "}"
33 | ]
34 | },
35 | "Block Save component": {
36 | "prefix": [
37 | "rw",
38 | "block",
39 | "save"
40 | ],
41 | "description": "Create a Save component for custom block development.",
42 | "body": [
43 | "/**",
44 | " * React hook that is used to mark the block wrapper element.",
45 | " * It provides all the necessary props like the class name.",
46 | " *",
47 | " * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps",
48 | " */",
49 | "import { useBlockProps } from '@wordpress/block-editor';",
50 | "",
51 | "/**",
52 | " * The save function defines the way in which the different attributes should",
53 | " * be combined into the final markup, which is then serialized by the block",
54 | " * editor into `post_content`.",
55 | " *",
56 | " * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save",
57 | " *",
58 | " * @return {WPElement} Element to render.",
59 | " */",
60 | "export default function save() {",
61 | "\treturn (",
62 | "\t\t",
63 | "\t\t\t
Save
",
64 | "\t\t",
65 | "\t);",
66 | "}"
67 | ]
68 | },
69 | "Retrieve from the WordPress datastore": {
70 | "prefix": [
71 | "rw",
72 | "wp",
73 | "getEntityRecords",
74 | "get-data"
75 | ],
76 | "description": "Add getEntityRecords selector with isLoading and invalidateResolution.",
77 | "body": [
78 | "import { useSelect, useDispatch } from '@wordpress/data';",
79 | "",
80 | "const { data, isLoading } = useSelect((select) => {",
81 | "\treturn {",
82 | "\t\tdata: select('core').getEntityRecords('${1:entity}', '${2:type}', {${3}}),",
83 | "\t\tisLoading: select('core/data').isResolving('core', 'getEntityRecords', ['${1:entity}', '${2:type}', {${3}}]),",
84 | "\t};",
85 | "});",
86 | "",
87 | "const { invalidateResolution } = useDispatch('core/data');",
88 | "",
89 | "$LINE_COMMENT Call this function when needed to re-trigger the getEntityRecords call.",
90 | "const reQuery = () => {",
91 | "\tinvalidateResolution('core', 'getEntityRecords', ['${1:entity}', '${2:type}', {${3}}]);",
92 | "};"
93 | ]
94 | }
95 | }
--------------------------------------------------------------------------------
/snippets/webpack.json:
--------------------------------------------------------------------------------
1 | {
2 | "Custom entry points": {
3 | "prefix": [
4 | "rw",
5 | "webpack",
6 | "entrypoints"
7 | ],
8 | "description": "Create a webpack config with custom entry points",
9 | "body": [
10 | "$LINE_COMMENT Import the original config from the @wordpress/scripts package.",
11 | "const defaultConfig = require(\"@wordpress/scripts/config/webpack.config\");",
12 | "",
13 | "$LINE_COMMENT Import the helper to find and generate the entry points in the src directory",
14 | "const { getWebpackEntryPoints } = require(\"@wordpress/scripts/utils/config\");",
15 | "",
16 | "$LINE_COMMENT Add any a new entry point by extending the webpack config.",
17 | "module.exports = {",
18 | "\t...defaultConfig,",
19 | "\tentry: {",
20 | "\t\t...defaultConfig.entry(),",
21 | "\t\t${1:entry}: \"${2:path}\"",
22 | "\t},",
23 | "};"
24 | ]
25 | }
26 | }
--------------------------------------------------------------------------------
/src/constants.js:
--------------------------------------------------------------------------------
1 | const path = require( 'path' );
2 |
3 | // The root directory for the project.
4 | const ROOT_DIR = path.resolve( __dirname, '../' );
5 | // The directory that contains the snippet categories.
6 | const SNIPPET_DATA_DIR = path.join( ROOT_DIR, '/snippet-data/' );
7 | // Where the generated snippets will be saved.
8 | const VSCODE_SNIPPETS_DIR = path.join( ROOT_DIR, '/snippets/' );
9 | // The location of the README.md file.
10 | const README_FILE = path.join( ROOT_DIR, '/README.md' );
11 |
12 | // What are the keys that the .snip files can have.
13 | const ALLOWED_DATA_KEYS = [ 'title', 'prefix', 'body', 'description', 'file' ];
14 |
15 | // Export all the things
16 | module.exports = {
17 | ALLOWED_DATA_KEYS,
18 | ROOT_DIR,
19 | README_FILE,
20 | SNIPPET_DATA_DIR,
21 | VSCODE_SNIPPETS_DIR,
22 | };
23 |
--------------------------------------------------------------------------------
/src/generate-readme.js:
--------------------------------------------------------------------------------
1 | const fs = require( 'fs' );
2 | const { basename } = require( 'path' );
3 | const { README_FILE } = require( './constants' );
4 | const {
5 | getSnippetDirectories,
6 | getSnippetData,
7 | } = require( './generate-snippets' );
8 |
9 | const TOKEN_START = '';
10 | const TOKEN_END = '';
11 | const TOKEN_REGEX =
12 | /(\<\!-- SNIPPET-TOC --\>)([\s\S]*)(\<\!-- \/SNIPPET-TOC --\>)/g;
13 |
14 | async function generateReadme() {
15 | const content = fs.readFileSync( README_FILE, 'utf-8' );
16 | const toc = await generateSnippetTables();
17 | const enhancedContent = await updateContentWithSnippetTable( content, toc );
18 |
19 | fs.writeFileSync( README_FILE, enhancedContent );
20 | }
21 |
22 | async function generateSnippetTables() {
23 | const dirs = await getSnippetDirectories();
24 | const data = await Promise.all(
25 | dirs.map( async ( dir ) => {
26 | const title = basename( dir );
27 | const snippetData = await getSnippetData( dir );
28 |
29 | return {
30 | title,
31 | snippetData,
32 | };
33 | } )
34 | );
35 | const content = data.reduce( ( markdown, { title, snippetData } ) => {
36 | const snippets = snippetData.reduce(
37 | ( snippetTable, { title: snippetTitle, prefix, description } ) => {
38 | return `${ snippetTable }| ${ snippetTitle } | ${ prefix.map(
39 | ( item ) => `\`${ item }\``
40 | ) } | ${ description } \n`;
41 | },
42 | '| Name | Snippet(s) | Description |\n| --- | --- | --- |\n'
43 | );
44 | return `${ markdown } ### ${ title }\n${ snippets }\n`;
45 | }, '' );
46 |
47 | const snippetTableContent = `
48 | \n
49 | ${ TOKEN_START }
50 |
51 | ## Snippets
52 | ${ content }
53 | ${ TOKEN_END }
54 | `;
55 |
56 | return snippetTableContent.trim();
57 | }
58 |
59 | async function updateContentWithSnippetTable( content, snippetTableContent ) {
60 | let nextContent = content;
61 | const [ match ] = nextContent.match( TOKEN_REGEX );
62 |
63 | if ( ! match ) {
64 | nextContent += snippetTableContent;
65 | } else {
66 | nextContent = nextContent.replace( match, snippetTableContent );
67 | }
68 | return nextContent;
69 | }
70 |
71 | // Start the show
72 | generateReadme();
73 |
--------------------------------------------------------------------------------
/src/generate-snippets.js:
--------------------------------------------------------------------------------
1 | const fs = require( 'fs' );
2 | const path = require( 'path' );
3 | const glob = require( 'glob' );
4 | const matter = require( 'gray-matter' );
5 | const { SNIPPET_DATA_DIR, VSCODE_SNIPPETS_DIR } = require( './constants' );
6 |
7 | async function generateSnippets() {
8 | const snippetDirs = await getSnippetDirectories();
9 | snippetDirs.map( async ( dir ) => {
10 | const data = await getSnippetData( dir );
11 | const snippetData = data.reduce( ( map, item ) => {
12 | const { title, description, body, prefix } = item;
13 | map[ title ] = {
14 | prefix,
15 | description,
16 | body,
17 | };
18 | return map;
19 | }, {} );
20 | const content = JSON.stringify( snippetData, null, 2 );
21 |
22 | fs.writeFile(
23 | path.join( VSCODE_SNIPPETS_DIR + path.basename( dir ) + '.json' ),
24 | content,
25 | ( err ) => {
26 | if ( err ) {
27 | // eslint-disable-next-line no-console
28 | console.log( err );
29 | }
30 | }
31 | );
32 | } );
33 | }
34 |
35 | async function getSnippetData( dir ) {
36 | const files = glob.sync( dir + '/*.snip' );
37 | const snippets = files.map( ( file ) => {
38 | const fileContent = fs.readFileSync( file, 'utf-8' );
39 | const markdownData = matter( fileContent );
40 | const {
41 | content: originalContent,
42 | data: { prefix: originalPrefix, ...restOfData },
43 | } = markdownData;
44 | const body = originalContent.trim().split( '\n' );
45 | const prefix = originalPrefix.split( '|' );
46 |
47 | return {
48 | ...restOfData,
49 | prefix,
50 | body,
51 | file,
52 | };
53 | } );
54 | return snippets;
55 | }
56 |
57 | async function getSnippetDirectories() {
58 | return glob.sync( SNIPPET_DATA_DIR + '*' );
59 | }
60 | exports.getSnippetDirectories = getSnippetDirectories;
61 | exports.getSnippetData = getSnippetData;
62 |
63 | generateSnippets();
64 |
--------------------------------------------------------------------------------
/src/lint-snippet-data.js:
--------------------------------------------------------------------------------
1 | const path = require( 'path' );
2 |
3 | const {
4 | getSnippetDirectories,
5 | getSnippetData,
6 | } = require( './generate-snippets' );
7 |
8 | const { ALLOWED_DATA_KEYS } = require( './constants' );
9 |
10 | async function lintSnippets() {
11 | const dirs = await getSnippetDirectories();
12 | await Promise.all(
13 | dirs.map( async ( dir ) => {
14 | const title = path.basename( dir );
15 | const snippetData = await getSnippetData( dir );
16 |
17 | // Reduce the array.
18 | try {
19 | snippetData.reduce( ( arr, item ) => {
20 | const {
21 | title: snippetTitle,
22 | prefix,
23 | description,
24 | file,
25 | } = item;
26 | const disallowedKeys = Object.keys( item ).filter(
27 | ( key ) => ! ALLOWED_DATA_KEYS.includes( key )
28 | );
29 |
30 | if ( disallowedKeys.length > 0 ) {
31 | throw new Error(
32 | `Unknown keys \`${ disallowedKeys.join() }\` found in ${ path.basename(
33 | file
34 | ) }`
35 | );
36 | }
37 |
38 | if ( ! snippetTitle || ! prefix || ! description ) {
39 | throw new Error(
40 | `Title, Prefix and Description items cannot be empty in ${ path.basename(
41 | file
42 | ) }`
43 | );
44 | }
45 |
46 | return arr;
47 | }, [] );
48 | } catch ( error ) {
49 | // eslint-disable-next-line no-console
50 | console.log( error );
51 | }
52 |
53 | return {
54 | title,
55 | snippetData,
56 | };
57 | } )
58 | );
59 | }
60 |
61 | lintSnippets();
62 |
--------------------------------------------------------------------------------