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 a flex layout abstraction #6

Open
StarLederer opened this issue Feb 11, 2023 · 12 comments
Open

Add a flex layout abstraction #6

StarLederer opened this issue Feb 11, 2023 · 12 comments
Labels
enhancement New feature or request requires triage Additinal research or evaluation required

Comments

@StarLederer
Copy link
Owner

Originally posted by @jojojojojoj5564656465465

Would you be abble to add this to Windblade ;

image

@StarLederer
Copy link
Owner Author

I am not quite understanding what you mean. What do the numbers mean, maximum elements in a row/column?

@jojojojojoj5564656465465

The number is the location area where the child div must be

the

is divided in 9 areas and it make easy to locate where you would like to place the child div

@jojojojojoj5564656465465

image

@jojojojojoj5564656465465
.flex-row-1{
display: flex
justify-content: start
align-items: start;
}

@jojojojojoj5564656465465
Copy link

jojojojojoj5564656465465 commented Feb 11, 2023

/^flex-(row|col)-(\d)$/

@StarLederer
Copy link
Owner Author

StarLederer commented Feb 11, 2023

Doesn't order-{number} already solve that? It is a Tailwind utility already present in Windblade that can change where the item is placed within a grid or flexbox.

@jojojojojoj5564656465465

no more need to lear justify-start or item-end

@jojojojojoj5564656465465

Peek 12-02-2023 01-59

It's working now hope it ll be in your preset

@jojojojojoj5564656465465
Copy link

jojojojojoj5564656465465 commented Feb 12, 2023

rules: [
    [
      /^flex-(row|col)-(\d)$/,
      ([, direction, number]) => {
        function dd(d: 'row' | 'col'): string {
          if (d === 'row') {
            return 'row'
          } else {
            return 'column'
          }
        }
        function area(n: number): string {
          let position: string[]
          switch (n) {
            case 1:
              position = ['start', 'start']
              break
            case 2:
              position = ['center', 'start']
              break
            case 3:
              position = ['end', 'start']
              break
            case 4:
              position = ['start', 'center']
              break
            case 5:
              position = ['center', 'center']
              break
            case 6:
              position = ['end', 'center']
              break
            case 7:
              position = ['start', 'end']
              break
            case 8:
              position = ['center', 'end']
              break
            case 9:
              position = ['end', 'end']
              break

            default:
              position = []
              break
          }
          return position
        }

        let direction2 = dd(direction as 'row' | 'col')
        let number2 = area(Number(number))
        return {
          display: 'flex',
          'flex-direction': direction2,
          'justify-content': number2[0],
          'align-items': number2[1],
        }
      },
    ]

@StarLederer
Copy link
Owner Author

StarLederer commented Feb 12, 2023

Oh I get it now, that does seem quite convenient but Windblade aims to be similar to Tailwind in utility names and functions and I don't think this abstraction fits in.

An alternative that I think fits better would be to use logical values (e.g flex-row-(ss|be|es)) but even then this ignores options like 'justify-content: space-between' and unnecessarily abstracts align-content. In fact I already removed Space Between, Divide and Ring originally found in Tailwind because they pretend to be CSS features and can crate confusion when used together with Margin, Border and Shadow.

I think your idea is pretty useful so you should probably publish it as your own small preset that can be used together with others. I can help you setting it up if you need.

At the same time, I remain open to adding it in the future if we determine that more abstraction is useful, this would require testing with large group of developers which is not possible at the moment.

@StarLederer StarLederer added the requires triage Additinal research or evaluation required label Feb 12, 2023
@StarLederer StarLederer changed the title Add unusual flex utility Add a flex layout abstraction Feb 12, 2023
@StarLederer StarLederer added the enhancement New feature or request label Feb 12, 2023
@jojojojojoj5564656465465

Thank you very much.

What do you think of doing a Separate file windblade.config.ts where user could activate or desactivate community rules like mine.

Windblade could become a directory of rules and any one could do

{
Flex-triks:true
Nth-chilllll:false
}

You would have to store all the community rules and leave user decide what would help or not

@StarLederer
Copy link
Owner Author

StarLederer commented Feb 12, 2023

I this is a great idea but that is also what UnoCSS already does itself so I really don't think we should make this part of Windblade.

You can have many presets at the same time so instead of

import { defineConfig } from 'unocss';
import presetWindblade from 'unocss-preset-windblade';

export default defineConfig({
  presets: [
    presetWindblade({
      flexTricks: true,
    }),
  ],
});

you just do

import { defineConfig } from 'unocss';
import presetWindblade from 'unocss-preset-windblade';
import presetFlexTricks from 'unocss-preset-flex-tricks'; // you'll need to publish it on NPM

export default defineConfig({
  presets: [
    presetWindblade(),
    presetFlexTricks(),
  ],
});

Once Windblade documentation is done I will reach out to @antfu (the creator of UnoCSS) to discuss if my documentation framework can be adopted in official UnoCSS presets and if we can collaborate on turning my documentation page into a visual library and documentation inspector of all compatible community presets (similar to Nuxt modules page) so they have a better chance at getting discovered.

If you want to start a discussion about this please do so here instead of replying in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request requires triage Additinal research or evaluation required
Projects
None yet
Development

No branches or pull requests

2 participants