-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create-block package: External Project Template Custom prompts? #47524
Comments
@eduwass, great thinking. That has crossed my mind a few times to allow defining custom prompts in external templates. I'd be more than happy to see a proof of concept for how that would work best from the perspective of someone willing to offer additional customizations for the tool. |
Thanks @gziolo appreciate it, if I have some free time from work to put aside into this I'll look into it. |
+1 to this idea. These additional prompts could be defined in the |
Hi @ryanwelcher So I opened this a long time ago, but since you pinged me here and I had some time I've played around with the idea today in a POC. You can see the fork here. Quick DemoI think this contains a couple of examples of how I'd envision this working: 000445.mp4Heres the code for: my-template/index.js
/**
* Dependencies
*/
const { join } = require("path");
module.exports = {
defaultValues: {
title: "My Template",
description: "My Template Description",
icon: "admin-post",
// Default values for custom prompts
analyticsId: 'UA-11111-2',
colorScheme: 'default',
enableAdvancedFeatures: false,
customCssPrefix: 'default-prefix-',
},
customPrompts: {
analyticsId: {
type: 'input',
name: 'analyticsId',
message: 'Enter your Google Analytics ID (optional, format: UA-XXXXX-Y):',
validate(input) {
if (!input) return true; // Optional
if (!/^UA-\d+-\d+$/.test(input)) {
return 'Invalid Google Analytics ID format. Should be like UA-XXXXX-Y';
}
return true;
}
},
colorScheme: {
type: 'list',
name: 'colorScheme',
message: 'Choose a color scheme for your block:',
choices: [
{ name: 'Default Theme Colors', value: 'default' },
{ name: 'Custom Palette', value: 'custom' },
{ name: 'Monochrome', value: 'mono' }
],
default: 'default'
},
enableAdvancedFeatures: {
type: 'confirm',
name: 'enableAdvancedFeatures',
message: 'Would you like to enable advanced block features?',
default: false
},
customCssPrefix: {
type: 'input',
name: 'customCssPrefix',
message: 'Enter a custom CSS prefix for your block (optional):',
validate(input) {
if (!input) return true; // Optional
if (!/^[a-z][a-z0-9-]*$/.test(input)) {
return 'CSS prefix must start with a letter and contain only lowercase letters, numbers, and hyphens';
}
return true;
},
filter(input) {
return input.toLowerCase();
}
}
},
// Make sure template files are found
pluginTemplatesPath: join(__dirname, 'files', 'plugin'),
blockTemplatesPath: join(__dirname, 'files', 'block'),
}; So far...
This is still barebones but just tried to get a working proof-of-concept as a starting point. Open Questions/ChallengesSeveral areas still need investigation and testing:
What do you think? Any thoughts on the above points? Thanks! |
This is great start! I'd open a PR based on your fork and we can go from there. |
@ryanwelcher OK great, I just created the initial PR here: #67806 |
What problem does this address?
When creating a new block or plugin using the @create-block package we are limited to a certain number of parameters that we are prompted, it would be awesome if we could add more to the list, based on our custom configuration.
See: https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/prompts.js
If this is already possible and I'm missing something, please let me know!
What is your proposed solution?
In this file: https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/templates.js#L220
There is a getDefaultValues and getPrompts, maybe when someone defines params DefaultValues that are not predefined, we still prompt for them so they are later available in mustache when scaffolding the block?
The text was updated successfully, but these errors were encountered: