diff --git a/packages/less/src/less/functions/index.js b/packages/less/src/less/functions/index.js index 160ac7523..51fa81f53 100644 --- a/packages/less/src/less/functions/index.js +++ b/packages/less/src/less/functions/index.js @@ -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 }; @@ -30,6 +31,7 @@ export default environment => { functionRegistry.addMultiple(svg(environment)); functionRegistry.addMultiple(types); functionRegistry.addMultiple(style); + functionRegistry.addMultiple(scrollState); return functions; }; diff --git a/packages/less/src/less/functions/scroll-state.js b/packages/less/src/less/functions/scroll-state.js new file mode 100644 index 000000000..fea922da4 --- /dev/null +++ b/packages/less/src/less/functions/scroll-state.js @@ -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) {} + }, +}; diff --git a/packages/test-data/css/_main/container.css b/packages/test-data/css/_main/container.css index f5a17a602..c710e5f43 100644 --- a/packages/test-data/css/_main/container.css +++ b/packages/test-data/css/_main/container.css @@ -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%; + } +} diff --git a/packages/test-data/less/_main/container.less b/packages/test-data/less/_main/container.less index 73fd17be0..cb02b49e0 100644 --- a/packages/test-data/less/_main/container.less +++ b/packages/test-data/less/_main/container.less @@ -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%; + } +}