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

CSS scroll state container queries #4311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/less/src/less/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import string from './string';
import svg from './svg';
import types from './types';
import style from './style';
import scrollState from './scroll-state';

export default environment => {
const functions = { functionRegistry, functionCaller };
Expand All @@ -30,6 +31,7 @@ export default environment => {
functionRegistry.addMultiple(svg(environment));
functionRegistry.addMultiple(types);
functionRegistry.addMultiple(style);
functionRegistry.addMultiple(scrollState);

return functions;
};
23 changes: 23 additions & 0 deletions packages/less/src/less/functions/scroll-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Variable from '../tree/variable';
import Anonymous from '../tree/variable';

const scrollStateExpression = function (args) {
args = Array.prototype.slice.call(args);
switch (args.length) {
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
}

const entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];

args = entityList.map(a => { return a.toCSS(this.context); }).join(this.context.compress ? ',' : ', ');

return new Anonymous(`scroll-state(${args})`);
};

export default {
'scroll-state': function(...args) {
try {
return scrollStateExpression.call(this, args);
} catch (e) {}
},
};
19 changes: 19 additions & 0 deletions packages/test-data/css/_main/container.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,22 @@
color: purple;
}
}
#sticky {
position: sticky;
container-type: scroll-state;
}
@container scroll-state (stuck: top) {
#sticky-child {
font-size: 75%;
}
}
@container scroll-state (snapped: x) {
#sticky-child {
font-size: 75%;
}
}
@container scroll-state (scrollable: top) {
#sticky-child {
font-size: 75%;
}
}
23 changes: 23 additions & 0 deletions packages/test-data/less/_main/container.less
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,26 @@
color: purple;
}
}

#sticky {
position: sticky;
container-type: scroll-state;
}

@container scroll-state(stuck: top) {
#sticky-child {
font-size: 75%;
}
}

@container scroll-state(snapped: x) {
#sticky-child {
font-size: 75%;
}
}

@container scroll-state(scrollable: top) {
#sticky-child {
font-size: 75%;
}
}
Loading