Skip to content
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

Add options to mixin file #62

Open
iammaxence opened this issue Oct 9, 2022 · 1 comment
Open

Add options to mixin file #62

iammaxence opened this issue Oct 9, 2022 · 1 comment

Comments

@iammaxence
Copy link

I'm currently working with tikui on a project and I regularly have components that change depending on an element.

Example:

mixin test-button(options)
  -const opt = options || {}
  -const classList = [];
  -if (opt.isRed) classList.push('-red');
  -if (opt.isBlue) { classList.push('-blue') };
  -const classes = classList.length > 0 ? classList.join(' ') : null;
  button.test-button(disabled=opt.isDisabled, class=classes)

I would like to propose that we add to CLI the possibility to add options to mixin:

program
    .command('create <component> [destination]')
    .option('-p, --prefix <name>', 'prefix')
    .option('-mo, --mixin-options', 'add options parameter to mixin')
    .description('create a component.')
    .addHelpText('after', '\nExample:\n $ tikui create -p tikui component src/atom')
    .action((component, destination, options) => {
      createComponent(destination, component, options.prefix, options.mixinOptions);
      console.log(`Creating component ${component} to ${path.resolve(destination)}`); // eslint-disable-line no-console
    });

To get this result :

mixin test-component(options)
  -const opt = options || {};
  -const classList = [];
  -const classes = classList.length > 0 ? classList.join(' ') : null;
  .test-component(class=classes) test-component

The createMixin function will be like this:

const createMixin = (componentDirectory: string, component: string, prefix?: string, mixinOptions?: boolean): void => {
  let content = `mixin ${dashPrefix(prefix)}${component}\n  .${dashPrefix(prefix)}${component} ${component}\n`;
  if(mixinOptions){
    content = `mixin ${dashPrefix(prefix)}${component}(options)
    -const opt = options || {};
    -const classList = [];
    -const classes = classList.length > 0 ? classList.join(' ') : null;
    .${dashPrefix(prefix)}${component}(class=classes) ${component}\n`;

  }
  const file = `${component}.mixin.pug`;
  createFile(componentDirectory, file);
  fs.writeFileSync(path.resolve(componentDirectory, file), content);
};

What do you think ?

@Gnuk
Copy link
Member

Gnuk commented Oct 10, 2022

You can propose a PR for it, i'm not sure -mo will work because multiple characters options needs two dash.

I've no idea if it will be really useful for Tikui users but let's try.

I know there is also a lack of documentation.

(On your PR, don't forget to refactor when needed ;) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants