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

pseudo classes with params #209

Merged
merged 34 commits into from
Feb 6, 2018
Merged

pseudo classes with params #209

merged 34 commits into from
Feb 6, 2018

Conversation

nadavwix
Copy link
Contributor

@nadavwix nadavwix commented Nov 28, 2017

Feature request: implement pseudo states with params.

Reason: Customization of data aware components ( AutoViews )

spec is found in pseudo classes readme.

  • process implementation in stylable - tom
  • implement in stylable - tom
  • process implementation in inteligence - ory
  • implement inteligence - ory
  • finalize readme - bruce & arnon
  • release notes - tom

@nadavwix nadavwix requested a review from idoros November 28, 2017 20:12
@tomrav tomrav added diagnostics Warnings and errors docs Documentation feature New syntax feature or behavior proposed spec labels Nov 29, 2017
@tomrav
Copy link
Collaborator

tomrav commented Jan 7, 2018

new and improved syntax:

/* 
* types and validators can be one and the same
* types/validarots are imported (optional)
* types/validators can have default values, e.g:  min vs min() useful for js validators
* values can have default values, e.g. -st-state(number, min(0), max(31)) 1;
* support multiple named params
* nesting validators - chain them one after the other, e.g. number(x()) === -st-state(number, x) 
*/

/* native types will not need to be imported, and would instead be available globally
:import {
	-st-from: "stylable-validations";
	-st-named: multiplyOf, min, max, number;
}
*/

:import {
	-st-from: "./my-validators.ts";
	-st-named: custom;
}

date:-st-states("[data-date='$day-$month-$year']") {
	day:	number(min(0), max(31)) 1;
	month: 	custom(multiplyOf 3, min 0, max 30) 1;
	year: 	number(multiplyOf(3), min(0), max(30)) 1980;
}

.root {
	-st-states: date
}

.a {
	-st-states: date
}

.a:date(day 1, month 10, year 2001){

}

.root {
	-st-states: x(string(contains('x')))
}

.token:fieldName(email){
color:lightBlue;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make string glob syntax identical to CSS.
fieldname($_id) does not look like it means 'ends with _id'
Make it fieldname($=_id) like CSS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that looks better, and more consistent with CSS.


```

#### Boolean example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this first example, make clear it is the default.
If it is possible to give an explicit Boolean parameter, give an example.

.cell{
-st-states: column(number);
-st-states: done(number<0,100>);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two -st-states in one class. Is this correct syntax? Better if it were
-st-states: column(number), done(number<0,100>);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two examples side by side, no intend to support multiple directives (you can add multiple states for a single directive, and that should be good enough)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but in an example it looks like it's supposed to be correct syntax, which it isn't.
I'd either have two states in the same line, or (better?) two classes side-by-side.
You want this to be copy-paste-able, IMO.

@brucelawson
Copy link
Contributor

Some notes while trying to get my head around this stuff after xmas break/ sickness:

rename -st-state as -custom-state instead; 'cause any example that has an -st- prefix looks like it's part of Stylable core/ reserved word

@brucelawson
Copy link
Contributor

i don't know the functionality implied by this example - but "multiplyOf" sounds alien to me. Is it "multiplyBy" so returns number*3, or "multipleOf" so returns true or false of number is perfectly divisible by 3?

const singleSelectorAst = sRule.selectorAst.nodes[0];
const selectorChunk = singleSelectorAst.nodes;

if (selectorChunk.length === 1 && selectorChunk[0].type === 'class') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refine with ido what about Elements

@tomrav tomrav merged commit 963174c into master Feb 6, 2018
@tomrav tomrav deleted the nadav/pseudo-state-params branch February 6, 2018 11:44
AviVahl pushed a commit that referenced this pull request May 23, 2018
Add support for pseudo classes with params (string, number, enum, tag) including validations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Warnings and errors docs Documentation feature New syntax feature or behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants