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

[Feature Proposal] Allow 'grid-' part to be optional when specifying grid columns #3533

Closed
4 tasks done
AndrewBogdanovTSS opened this issue Jan 26, 2024 · 2 comments · Fixed by #3542
Closed
4 tasks done

Comments

@AndrewBogdanovTSS
Copy link
Contributor

AndrewBogdanovTSS commented Jan 26, 2024

Clear and concise description of the problem

As a developer using UnoCSS I want to be able to use shorter utilities when spcifying grid column sizes

Suggested solution

https://github.com/search?type=code&q=repo:unocss/unocss%20%22%2F%5Egrid-(rows%7Ccols)-(%5Cd%2B)%24%2F%22

[/^?:grid-(rows|cols)-(\d+)$/, ([, c, d]) => ({ [`grid-template-${rowCol(c)}`]: `repeat(${d},minmax(0,1fr))` }), { autocomplete: ['grid-(rows|cols)-<num>', 'grid-(rows|cols)-none'] }],

grid- in the above regular expression should be optional pretty much the same as it's already done for grid auto flow utility

[/^(?:grid-auto-flow|auto-flow|grid-flow)-(.+)$/, ([, v]) => ({ 'grid-auto-flow': h.bracket.cssvar(v) })],

Alternative

Right now I just have to manually keep those rules in the project

import type { Rule } from 'unocss'
import { h } from '@unocss/preset-mini/utils'

function rowCol(s: string) {
  return s.replace('col', 'column')
}
function rowColTheme(s: string) {
  return s[0] === 'r' ? 'Row' : 'Column'
}

export const grids: Rule[] = [
  [/^(rows|cols)-(.+)$/, ([, c, v], { theme }) => ({
    [`grid-template-${rowCol(c)}`]: theme[`gridTemplate${rowColTheme(c)}`]?.[v] ?? h.bracket.cssvar(v)
  })],
  [/^(rows|cols)-minmax-([\w.-]+)$/, ([, c, d]) => ({
    [`grid-template-${rowCol(c)}`]: `repeat(auto-fill,minmax(${d},1fr))`
  })],
  [/^(rows|cols)-(\d+)$/, ([, c, d]) => ({
    [`grid-template-${rowCol(c)}`]: `repeat(${d},minmax(0,1fr))`
  }), { autocomplete: ['(rows|cols)-<num>', '(rows|cols)-none'] }]
]

but it would be great if that would come out of the box, given that the change is just about adding ?: to the regexp

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the README.md of using the package.
  • Already used the Interactive Docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@AndrewBogdanovTSS AndrewBogdanovTSS changed the title [Feature Proposal] Allow grid part to be optional when specifying grid columns [Feature Proposal] Allow 'grid-' part to be optional when specifying grid columns Jan 26, 2024
@antfu
Copy link
Member

antfu commented Jan 26, 2024

I am ok with it. PR welcome :)

@AndrewBogdanovTSS
Copy link
Contributor Author

@antfu ready for review

github-merge-queue bot pushed a commit that referenced this issue Mar 14, 2024
… (#3542)

Co-authored-by: Chris <hizyyv@gmail.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants