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

Improve clamp mixin #19

Open
kuuak opened this issue Jun 5, 2024 · 1 comment
Open

Improve clamp mixin #19

kuuak opened this issue Jun 5, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@kuuak
Copy link
Contributor

kuuak commented Jun 5, 2024

Make the clamp mixin handle an inverted slope

example:

@mixin clamp width, 65, 50, $min-bp, $max-bp;
@kuuak kuuak added the enhancement New feature or request label Jun 5, 2024
@kuuak
Copy link
Contributor Author

kuuak commented Jun 5, 2024

Suggestion from @snugglejuice

actuellement ce n'est pas supporté dans notre mixin. Il faudrait la modifier la fonction clamp pour le calcul de la slope pour que le max - min prenne effectivement le plus grand nombre et modifier aussi dans le return pour que le premier soit bien le plus petit et le deuxième le plus grand

module.exports = {
	clamp(mixin, property, minPx, maxPx, minBp, maxBp) {
		const toRems = (px) => {
			return px / 16;
		};
		const rnd = (number, places = 0) => {
			let n = 1;
			if (places > 0) {
				for (let i = 1; i <= places; i++) {
					n = n * 10;
				}
			}
			return Math.round(number * n) / n;
		};

		// Remove px from breakpoints
		const strippedMinBp = minBp.replace(/px/g, '');
		const strippedMaxBp = maxBp.replace(/px/g, '');

		const slope = (minPx - maxPx) / (strippedMinBp - strippedMaxBp);
		const slopeVw = rnd(slope * 100, 2);
		const interceptRems = rnd(toRems(minPx - slope * strippedMinBp), 2);

		return {
			[property]: `clamp(${maxPx}px, ${slopeVw}vw + ${interceptRems}rem, ${minPx}px)`,
		};
	},
};

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

No branches or pull requests

1 participant