@purpurds/spacer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LICENSE.txt +31 -0
- package/dist/metadata.js +9 -0
- package/dist/spacer.cjs.js +2 -0
- package/dist/spacer.cjs.js.map +1 -0
- package/dist/spacer.d.ts +18 -0
- package/dist/spacer.d.ts.map +1 -0
- package/dist/spacer.es.js +96 -0
- package/dist/spacer.es.js.map +1 -0
- package/dist/styles.css +1 -0
- package/eslint.config.mjs +2 -0
- package/package.json +70 -0
- package/src/global.d.ts +4 -0
- package/src/spacer.module.scss +164 -0
- package/src/spacer.stories.tsx +127 -0
- package/src/spacer.test.tsx +152 -0
- package/src/spacer.tsx +46 -0
package/dist/LICENSE.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Name: classnames
|
|
2
|
+
Version: 2.5.1
|
|
3
|
+
License: MIT
|
|
4
|
+
Private: false
|
|
5
|
+
Description: A simple utility for conditionally joining classNames together
|
|
6
|
+
Repository: git+https://github.com/JedWatson/classnames.git
|
|
7
|
+
Author: Jed Watson
|
|
8
|
+
License Copyright:
|
|
9
|
+
===
|
|
10
|
+
|
|
11
|
+
The MIT License (MIT)
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2018 Jed Watson
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime");function d(p){return p&&p.__esModule&&Object.prototype.hasOwnProperty.call(p,"default")?p.default:p}var h={exports:{}};var x;function n(){return x||(x=1,(function(p){(function(){var t={}.hasOwnProperty;function u(){for(var r="",e=0;e<arguments.length;e++){var s=arguments[e];s&&(r=a(r,_.call(this,s)))}return r}function _(r){if(typeof r=="string"||typeof r=="number")return this&&this[r]||r;if(typeof r!="object")return"";if(Array.isArray(r))return u.apply(this,r);if(r.toString!==Object.prototype.toString&&!r.toString.toString().includes("[native code]"))return r.toString();var e="";for(var s in r)t.call(r,s)&&r[s]&&(e=a(e,this&&this[s]||s));return e}function a(r,e){return e?r?r+" "+e:r+e:r}p.exports?(u.default=u,p.exports=u):window.classNames=u})()})(h)),h.exports}var l=n();const o=d(l),g={"purpur-spacer--width-xxxs":"_purpur-spacer--width-xxxs_1ehtd_1","purpur-spacer--width-xxs":"_purpur-spacer--width-xxs_1ehtd_4","purpur-spacer--width-xs":"_purpur-spacer--width-xs_1ehtd_7","purpur-spacer--width-sm":"_purpur-spacer--width-sm_1ehtd_10","purpur-spacer--width-md":"_purpur-spacer--width-md_1ehtd_13","purpur-spacer--width-lg":"_purpur-spacer--width-lg_1ehtd_16","purpur-spacer--width-xl":"_purpur-spacer--width-xl_1ehtd_19","purpur-spacer--width-xxl":"_purpur-spacer--width-xxl_1ehtd_22","purpur-spacer--width-xxxl":"_purpur-spacer--width-xxxl_1ehtd_25","purpur-spacer--height-xxxs":"_purpur-spacer--height-xxxs_1ehtd_28","purpur-spacer--height-xxs":"_purpur-spacer--height-xxs_1ehtd_31","purpur-spacer--height-xs":"_purpur-spacer--height-xs_1ehtd_34","purpur-spacer--height-sm":"_purpur-spacer--height-sm_1ehtd_37","purpur-spacer--height-md":"_purpur-spacer--height-md_1ehtd_40","purpur-spacer--height-lg":"_purpur-spacer--height-lg_1ehtd_43","purpur-spacer--height-xl":"_purpur-spacer--height-xl_1ehtd_46","purpur-spacer--height-xxl":"_purpur-spacer--height-xxl_1ehtd_49","purpur-spacer--height-xxxl":"_purpur-spacer--height-xxxl_1ehtd_52","purpur-spacer":"_purpur-spacer_1ehtd_1","purpur-spacer--dynamic":"_purpur-spacer--dynamic_1ehtd_60","purpur-spacer--half":"_purpur-spacer--half_1ehtd_71","purpur-spacer--bg-xxxs":"_purpur-spacer--bg-xxxs_1ehtd_87","purpur-spacer--bg-xxs":"_purpur-spacer--bg-xxs_1ehtd_90","purpur-spacer--bg-xs":"_purpur-spacer--bg-xs_1ehtd_93","purpur-spacer--bg-sm":"_purpur-spacer--bg-sm_1ehtd_96","purpur-spacer--bg-md":"_purpur-spacer--bg-md_1ehtd_99","purpur-spacer--bg-lg":"_purpur-spacer--bg-lg_1ehtd_102","purpur-spacer--bg-xl":"_purpur-spacer--bg-xl_1ehtd_105","purpur-spacer--bg-xxl":"_purpur-spacer--bg-xxl_1ehtd_108","purpur-spacer--bg-xxxl":"_purpur-spacer--bg-xxxl_1ehtd_111"},f=o.bind(g),c="purpur-spacer",b=["xxxs","xxs","xs","sm","md","lg","xl","xxl","xxxl"],m=({width:p,height:t,dynamic:u=!1,half:_,background:a,className:r,...e})=>i.jsx("div",{...e,className:f(r,c,{[`${c}--width-${p}`]:p,[`${c}--height-${t}`]:t,[`${c}--dynamic`]:u,[`${c}--half`]:_,[`${c}--bg-${p||t}`]:a&&(p||t)})});exports.SPACER_SIZE=b;exports.Spacer=m;
|
|
2
|
+
//# sourceMappingURL=spacer.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacer.cjs.js","sources":["../../../common/temp/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/bind.js","../src/spacer.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue.call(this, arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn this && this[arg] || arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(this, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, this && this[key] || key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import React from \"react\";\nimport type { BaseProps } from \"@purpurds/common-types\";\nimport c from \"classnames/bind\";\n\nimport styles from \"./spacer.module.scss\";\n\nconst cx = c.bind(styles);\nconst rootClassName = \"purpur-spacer\";\n\nexport const SPACER_SIZE = [\"xxxs\", \"xxs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"xxl\", \"xxxl\"] as const;\n\nexport type SpacerSize = (typeof SPACER_SIZE)[number];\n\nexport type SpacerProps = Omit<BaseProps, \"children\"> & {\n /** Width spacing size (horizontal) */\n width?: SpacerSize;\n /** Height spacing size (vertical) */\n height?: SpacerSize;\n /** Whether the spacer scales with breakpoints. Default is true (dynamic). */\n dynamic?: boolean;\n /** Divide the size in half */\n half?: boolean;\n /** Show background color based on size (for presentation/debugging) */\n background?: boolean;\n};\n\nexport const Spacer = ({\n width,\n height,\n dynamic = false,\n half,\n background,\n className,\n ...props\n}: SpacerProps) => (\n <div\n {...props}\n className={cx(className, rootClassName, {\n [`${rootClassName}--width-${width}`]: width,\n [`${rootClassName}--height-${height}`]: height,\n [`${rootClassName}--dynamic`]: dynamic,\n [`${rootClassName}--half`]: half,\n [`${rootClassName}--bg-${width || height}`]: background && (width || height),\n })}\n />\n);\n"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","cx","c","styles","rootClassName","SPACER_SIZE","Spacer","width","height","dynamic","half","background","className","props","jsx"],"mappings":"4RAOC,UAAY,CAGZ,IAAIA,EAAS,CAAA,EAAG,eAEhB,SAASC,GAAc,CAGtB,QAFIC,EAAU,GAELC,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAAK,CAC1C,IAAIC,EAAM,UAAUD,CAAC,EACjBC,IACHF,EAAUG,EAAYH,EAASI,EAAW,KAAK,KAAMF,CAAG,CAAC,EAE7D,CAEE,OAAOF,CACT,CAEC,SAASI,EAAYF,EAAK,CACzB,GAAI,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,SAC7C,OAAO,MAAQ,KAAKA,CAAG,GAAKA,EAG7B,GAAI,OAAOA,GAAQ,SAClB,MAAO,GAGR,GAAI,MAAM,QAAQA,CAAG,EACpB,OAAOH,EAAW,MAAM,KAAMG,CAAG,EAGlC,GAAIA,EAAI,WAAa,OAAO,UAAU,UAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe,EAClG,OAAOA,EAAI,SAAQ,EAGpB,IAAIF,EAAU,GAEd,QAASK,KAAOH,EACXJ,EAAO,KAAKI,EAAKG,CAAG,GAAKH,EAAIG,CAAG,IACnCL,EAAUG,EAAYH,EAAS,MAAQ,KAAKK,CAAG,GAAKA,CAAG,GAIzD,OAAOL,CACT,CAEC,SAASG,EAAaG,EAAOC,EAAU,CACtC,OAAKA,EAIDD,EACIA,EAAQ,IAAMC,EAGfD,EAAQC,EAPPD,CAQV,CAEsCE,EAAO,SAC3CT,EAAW,QAAUA,EACrBS,UAAiBT,GAOjB,OAAO,WAAaA,CAEtB,s1DCtEMU,EAAKC,EAAE,KAAKC,CAAM,EAClBC,EAAgB,gBAETC,EAAc,CAAC,OAAQ,MAAO,KAAM,KAAM,KAAM,KAAM,KAAM,MAAO,MAAM,EAiBzEC,EAAS,CAAC,CACrB,MAAAC,EACA,OAAAC,EACA,QAAAC,EAAU,GACV,KAAAC,EACA,WAAAC,EACA,UAAAC,EACA,GAAGC,CACL,IACEC,EAAAA,IAAC,MAAA,CACE,GAAGD,EACJ,UAAWZ,EAAGW,EAAWR,EAAe,CACtC,CAAC,GAAGA,CAAa,WAAWG,CAAK,EAAE,EAAGA,EACtC,CAAC,GAAGH,CAAa,YAAYI,CAAM,EAAE,EAAGA,EACxC,CAAC,GAAGJ,CAAa,WAAW,EAAGK,EAC/B,CAAC,GAAGL,CAAa,QAAQ,EAAGM,EAC5B,CAAC,GAAGN,CAAa,QAAQG,GAASC,CAAM,EAAE,EAAGG,IAAeJ,GAASC,EAAA,CACtE,CAAA,CACH","x_google_ignoreList":[0]}
|
package/dist/spacer.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseProps } from '@purpurds/common-types';
|
|
3
|
+
export declare const SPACER_SIZE: readonly ["xxxs", "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
|
|
4
|
+
export type SpacerSize = (typeof SPACER_SIZE)[number];
|
|
5
|
+
export type SpacerProps = Omit<BaseProps, "children"> & {
|
|
6
|
+
/** Width spacing size (horizontal) */
|
|
7
|
+
width?: SpacerSize;
|
|
8
|
+
/** Height spacing size (vertical) */
|
|
9
|
+
height?: SpacerSize;
|
|
10
|
+
/** Whether the spacer scales with breakpoints. Default is true (dynamic). */
|
|
11
|
+
dynamic?: boolean;
|
|
12
|
+
/** Divide the size in half */
|
|
13
|
+
half?: boolean;
|
|
14
|
+
/** Show background color based on size (for presentation/debugging) */
|
|
15
|
+
background?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const Spacer: ({ width, height, dynamic, half, background, className, ...props }: SpacerProps) => React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=spacer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacer.d.ts","sourceRoot":"","sources":["../src/spacer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAQxD,eAAO,MAAM,WAAW,uEAAwE,CAAC;AAEjG,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IACtD,sCAAsC;IACtC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,qCAAqC;IACrC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8BAA8B;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,mEAQpB,WAAW,sBAWb,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
function d(p) {
|
|
3
|
+
return p && p.__esModule && Object.prototype.hasOwnProperty.call(p, "default") ? p.default : p;
|
|
4
|
+
}
|
|
5
|
+
var a = { exports: {} };
|
|
6
|
+
var x;
|
|
7
|
+
function n() {
|
|
8
|
+
return x || (x = 1, (function(p) {
|
|
9
|
+
(function() {
|
|
10
|
+
var t = {}.hasOwnProperty;
|
|
11
|
+
function u() {
|
|
12
|
+
for (var r = "", e = 0; e < arguments.length; e++) {
|
|
13
|
+
var s = arguments[e];
|
|
14
|
+
s && (r = _(r, h.call(this, s)));
|
|
15
|
+
}
|
|
16
|
+
return r;
|
|
17
|
+
}
|
|
18
|
+
function h(r) {
|
|
19
|
+
if (typeof r == "string" || typeof r == "number")
|
|
20
|
+
return this && this[r] || r;
|
|
21
|
+
if (typeof r != "object")
|
|
22
|
+
return "";
|
|
23
|
+
if (Array.isArray(r))
|
|
24
|
+
return u.apply(this, r);
|
|
25
|
+
if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
|
|
26
|
+
return r.toString();
|
|
27
|
+
var e = "";
|
|
28
|
+
for (var s in r)
|
|
29
|
+
t.call(r, s) && r[s] && (e = _(e, this && this[s] || s));
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
function _(r, e) {
|
|
33
|
+
return e ? r ? r + " " + e : r + e : r;
|
|
34
|
+
}
|
|
35
|
+
p.exports ? (u.default = u, p.exports = u) : window.classNames = u;
|
|
36
|
+
})();
|
|
37
|
+
})(a)), a.exports;
|
|
38
|
+
}
|
|
39
|
+
var l = n();
|
|
40
|
+
const o = /* @__PURE__ */ d(l), g = {
|
|
41
|
+
"purpur-spacer--width-xxxs": "_purpur-spacer--width-xxxs_1ehtd_1",
|
|
42
|
+
"purpur-spacer--width-xxs": "_purpur-spacer--width-xxs_1ehtd_4",
|
|
43
|
+
"purpur-spacer--width-xs": "_purpur-spacer--width-xs_1ehtd_7",
|
|
44
|
+
"purpur-spacer--width-sm": "_purpur-spacer--width-sm_1ehtd_10",
|
|
45
|
+
"purpur-spacer--width-md": "_purpur-spacer--width-md_1ehtd_13",
|
|
46
|
+
"purpur-spacer--width-lg": "_purpur-spacer--width-lg_1ehtd_16",
|
|
47
|
+
"purpur-spacer--width-xl": "_purpur-spacer--width-xl_1ehtd_19",
|
|
48
|
+
"purpur-spacer--width-xxl": "_purpur-spacer--width-xxl_1ehtd_22",
|
|
49
|
+
"purpur-spacer--width-xxxl": "_purpur-spacer--width-xxxl_1ehtd_25",
|
|
50
|
+
"purpur-spacer--height-xxxs": "_purpur-spacer--height-xxxs_1ehtd_28",
|
|
51
|
+
"purpur-spacer--height-xxs": "_purpur-spacer--height-xxs_1ehtd_31",
|
|
52
|
+
"purpur-spacer--height-xs": "_purpur-spacer--height-xs_1ehtd_34",
|
|
53
|
+
"purpur-spacer--height-sm": "_purpur-spacer--height-sm_1ehtd_37",
|
|
54
|
+
"purpur-spacer--height-md": "_purpur-spacer--height-md_1ehtd_40",
|
|
55
|
+
"purpur-spacer--height-lg": "_purpur-spacer--height-lg_1ehtd_43",
|
|
56
|
+
"purpur-spacer--height-xl": "_purpur-spacer--height-xl_1ehtd_46",
|
|
57
|
+
"purpur-spacer--height-xxl": "_purpur-spacer--height-xxl_1ehtd_49",
|
|
58
|
+
"purpur-spacer--height-xxxl": "_purpur-spacer--height-xxxl_1ehtd_52",
|
|
59
|
+
"purpur-spacer": "_purpur-spacer_1ehtd_1",
|
|
60
|
+
"purpur-spacer--dynamic": "_purpur-spacer--dynamic_1ehtd_60",
|
|
61
|
+
"purpur-spacer--half": "_purpur-spacer--half_1ehtd_71",
|
|
62
|
+
"purpur-spacer--bg-xxxs": "_purpur-spacer--bg-xxxs_1ehtd_87",
|
|
63
|
+
"purpur-spacer--bg-xxs": "_purpur-spacer--bg-xxs_1ehtd_90",
|
|
64
|
+
"purpur-spacer--bg-xs": "_purpur-spacer--bg-xs_1ehtd_93",
|
|
65
|
+
"purpur-spacer--bg-sm": "_purpur-spacer--bg-sm_1ehtd_96",
|
|
66
|
+
"purpur-spacer--bg-md": "_purpur-spacer--bg-md_1ehtd_99",
|
|
67
|
+
"purpur-spacer--bg-lg": "_purpur-spacer--bg-lg_1ehtd_102",
|
|
68
|
+
"purpur-spacer--bg-xl": "_purpur-spacer--bg-xl_1ehtd_105",
|
|
69
|
+
"purpur-spacer--bg-xxl": "_purpur-spacer--bg-xxl_1ehtd_108",
|
|
70
|
+
"purpur-spacer--bg-xxxl": "_purpur-spacer--bg-xxxl_1ehtd_111"
|
|
71
|
+
}, f = o.bind(g), c = "purpur-spacer", m = ["xxxs", "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"], w = ({
|
|
72
|
+
width: p,
|
|
73
|
+
height: t,
|
|
74
|
+
dynamic: u = !1,
|
|
75
|
+
half: h,
|
|
76
|
+
background: _,
|
|
77
|
+
className: r,
|
|
78
|
+
...e
|
|
79
|
+
}) => /* @__PURE__ */ i(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
...e,
|
|
83
|
+
className: f(r, c, {
|
|
84
|
+
[`${c}--width-${p}`]: p,
|
|
85
|
+
[`${c}--height-${t}`]: t,
|
|
86
|
+
[`${c}--dynamic`]: u,
|
|
87
|
+
[`${c}--half`]: h,
|
|
88
|
+
[`${c}--bg-${p || t}`]: _ && (p || t)
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
export {
|
|
93
|
+
m as SPACER_SIZE,
|
|
94
|
+
w as Spacer
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=spacer.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacer.es.js","sources":["../../../common/temp/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/bind.js","../src/spacer.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue.call(this, arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn this && this[arg] || arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(this, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, this && this[key] || key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import React from \"react\";\nimport type { BaseProps } from \"@purpurds/common-types\";\nimport c from \"classnames/bind\";\n\nimport styles from \"./spacer.module.scss\";\n\nconst cx = c.bind(styles);\nconst rootClassName = \"purpur-spacer\";\n\nexport const SPACER_SIZE = [\"xxxs\", \"xxs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"xxl\", \"xxxl\"] as const;\n\nexport type SpacerSize = (typeof SPACER_SIZE)[number];\n\nexport type SpacerProps = Omit<BaseProps, \"children\"> & {\n /** Width spacing size (horizontal) */\n width?: SpacerSize;\n /** Height spacing size (vertical) */\n height?: SpacerSize;\n /** Whether the spacer scales with breakpoints. Default is true (dynamic). */\n dynamic?: boolean;\n /** Divide the size in half */\n half?: boolean;\n /** Show background color based on size (for presentation/debugging) */\n background?: boolean;\n};\n\nexport const Spacer = ({\n width,\n height,\n dynamic = false,\n half,\n background,\n className,\n ...props\n}: SpacerProps) => (\n <div\n {...props}\n className={cx(className, rootClassName, {\n [`${rootClassName}--width-${width}`]: width,\n [`${rootClassName}--height-${height}`]: height,\n [`${rootClassName}--dynamic`]: dynamic,\n [`${rootClassName}--half`]: half,\n [`${rootClassName}--bg-${width || height}`]: background && (width || height),\n })}\n />\n);\n"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","cx","c","styles","rootClassName","SPACER_SIZE","Spacer","width","height","dynamic","half","background","className","props","jsx"],"mappings":";;;;;;;;AAOA,KAAC,WAAY;AAGZ,UAAIA,IAAS,CAAA,EAAG;AAEhB,eAASC,IAAc;AAGtB,iBAFIC,IAAU,IAELC,IAAI,GAAGA,IAAI,UAAU,QAAQA,KAAK;AAC1C,cAAIC,IAAM,UAAUD,CAAC;AACrB,UAAIC,MACHF,IAAUG,EAAYH,GAASI,EAAW,KAAK,MAAMF,CAAG,CAAC;AAAA,QAE7D;AAEE,eAAOF;AAAA,MACT;AAEC,eAASI,EAAYF,GAAK;AACzB,YAAI,OAAOA,KAAQ,YAAY,OAAOA,KAAQ;AAC7C,iBAAO,QAAQ,KAAKA,CAAG,KAAKA;AAG7B,YAAI,OAAOA,KAAQ;AAClB,iBAAO;AAGR,YAAI,MAAM,QAAQA,CAAG;AACpB,iBAAOH,EAAW,MAAM,MAAMG,CAAG;AAGlC,YAAIA,EAAI,aAAa,OAAO,UAAU,YAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe;AAClG,iBAAOA,EAAI,SAAQ;AAGpB,YAAIF,IAAU;AAEd,iBAASK,KAAOH;AACf,UAAIJ,EAAO,KAAKI,GAAKG,CAAG,KAAKH,EAAIG,CAAG,MACnCL,IAAUG,EAAYH,GAAS,QAAQ,KAAKK,CAAG,KAAKA,CAAG;AAIzD,eAAOL;AAAA,MACT;AAEC,eAASG,EAAaG,GAAOC,GAAU;AACtC,eAAKA,IAIDD,IACIA,IAAQ,MAAMC,IAGfD,IAAQC,IAPPD;AAAA,MAQV;AAEC,MAAqCE,EAAO,WAC3CT,EAAW,UAAUA,GACrBS,YAAiBT,KAOjB,OAAO,aAAaA;AAAA,IAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GCtEMU,IAAKC,EAAE,KAAKC,CAAM,GAClBC,IAAgB,iBAETC,IAAc,CAAC,QAAQ,OAAO,MAAM,MAAM,MAAM,MAAM,MAAM,OAAO,MAAM,GAiBzEC,IAAS,CAAC;AAAA,EACrB,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,GAAGC;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACE,GAAGD;AAAA,IACJ,WAAWZ,EAAGW,GAAWR,GAAe;AAAA,MACtC,CAAC,GAAGA,CAAa,WAAWG,CAAK,EAAE,GAAGA;AAAA,MACtC,CAAC,GAAGH,CAAa,YAAYI,CAAM,EAAE,GAAGA;AAAA,MACxC,CAAC,GAAGJ,CAAa,WAAW,GAAGK;AAAA,MAC/B,CAAC,GAAGL,CAAa,QAAQ,GAAGM;AAAA,MAC5B,CAAC,GAAGN,CAAa,QAAQG,KAASC,CAAM,EAAE,GAAGG,MAAeJ,KAASC;AAAA,IAAA,CACtE;AAAA,EAAA;AACH;","x_google_ignoreList":[0]}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._purpur-spacer--width-xxxs_1ehtd_1{--width-size: var(--purpur-spacing-50)}._purpur-spacer--width-xxs_1ehtd_4{--width-size: var(--purpur-spacing-100)}._purpur-spacer--width-xs_1ehtd_7{--width-size: var(--purpur-spacing-200)}._purpur-spacer--width-sm_1ehtd_10{--width-size: var(--purpur-spacing-300)}._purpur-spacer--width-md_1ehtd_13{--width-size: var(--purpur-spacing-400)}._purpur-spacer--width-lg_1ehtd_16{--width-size: var(--purpur-spacing-600)}._purpur-spacer--width-xl_1ehtd_19{--width-size: var(--purpur-spacing-800)}._purpur-spacer--width-xxl_1ehtd_22{--width-size: var(--purpur-spacing-1000)}._purpur-spacer--width-xxxl_1ehtd_25{--width-size: var(--purpur-spacing-1200)}._purpur-spacer--height-xxxs_1ehtd_28{--height-size: var(--purpur-spacing-50)}._purpur-spacer--height-xxs_1ehtd_31{--height-size: var(--purpur-spacing-100)}._purpur-spacer--height-xs_1ehtd_34{--height-size: var(--purpur-spacing-200)}._purpur-spacer--height-sm_1ehtd_37{--height-size: var(--purpur-spacing-300)}._purpur-spacer--height-md_1ehtd_40{--height-size: var(--purpur-spacing-400)}._purpur-spacer--height-lg_1ehtd_43{--height-size: var(--purpur-spacing-600)}._purpur-spacer--height-xl_1ehtd_46{--height-size: var(--purpur-spacing-800)}._purpur-spacer--height-xxl_1ehtd_49{--height-size: var(--purpur-spacing-1000)}._purpur-spacer--height-xxxl_1ehtd_52{--height-size: var(--purpur-spacing-1200)}._purpur-spacer_1ehtd_1{width:var(--width-size, 0);height:var(--height-size, 0)}@media (min-width: 600px){._purpur-spacer--dynamic_1ehtd_60{width:calc(var(--width-size, 0) * 1.5);height:calc(var(--height-size, 0) * 1.5)}}@media (min-width: 1024px){._purpur-spacer--dynamic_1ehtd_60{width:calc(var(--width-size, 0) * 2.5);height:calc(var(--height-size, 0) * 2.5)}}._purpur-spacer--half_1ehtd_71{width:calc(var(--width-size, 0) / 2);height:calc(var(--height-size, 0) / 2)}@media (min-width: 600px){._purpur-spacer--half_1ehtd_71._purpur-spacer--dynamic_1ehtd_60{width:calc(var(--width-size, 0) / 2 * 1.5);height:calc(var(--height-size, 0) / 2 * 1.5)}}@media (min-width: 1024px){._purpur-spacer--half_1ehtd_71._purpur-spacer--dynamic_1ehtd_60{width:calc(var(--width-size, 0) / 2 * 2.5);height:calc(var(--height-size, 0) / 2 * 2.5)}}._purpur-spacer--bg-xxxs_1ehtd_87{background-color:var(--purpur-color-purple-50)}._purpur-spacer--bg-xxs_1ehtd_90{background-color:var(--purpur-color-purple-100)}._purpur-spacer--bg-xs_1ehtd_93{background-color:var(--purpur-color-purple-200)}._purpur-spacer--bg-sm_1ehtd_96{background-color:var(--purpur-color-purple-300)}._purpur-spacer--bg-md_1ehtd_99{background-color:var(--purpur-color-purple-400)}._purpur-spacer--bg-lg_1ehtd_102{background-color:var(--purpur-color-purple-500)}._purpur-spacer--bg-xl_1ehtd_105{background-color:var(--purpur-color-purple-600)}._purpur-spacer--bg-xxl_1ehtd_108{background-color:var(--purpur-color-purple-700)}._purpur-spacer--bg-xxxl_1ehtd_111{background-color:var(--purpur-color-purple-800)}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purpurds/spacer",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"main": "./dist/spacer.cjs.js",
|
|
6
|
+
"types": "./dist/spacer.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/spacer.cjs.js",
|
|
10
|
+
"types": "./dist/spacer.d.ts",
|
|
11
|
+
"default": "./dist/spacer.es.js"
|
|
12
|
+
},
|
|
13
|
+
"./styles": "./dist/styles.css",
|
|
14
|
+
"./metadata": "./dist/metadata.js"
|
|
15
|
+
},
|
|
16
|
+
"source": "src/spacer.tsx",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"classnames": "~2.5.1",
|
|
19
|
+
"@purpurds/tokens": "8.16.3",
|
|
20
|
+
"@purpurds/common-types": "8.16.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@storybook/react-vite": "10.1.11",
|
|
24
|
+
"@testing-library/dom": "~10.4.1",
|
|
25
|
+
"@testing-library/jest-dom": "~6.9.1",
|
|
26
|
+
"@testing-library/react": "~16.3.0",
|
|
27
|
+
"@types/node": "22.17",
|
|
28
|
+
"@types/react-dom": "^19.2.3",
|
|
29
|
+
"@types/react": "^19.2.6",
|
|
30
|
+
"eslint": "9.39.2",
|
|
31
|
+
"jsdom": "~27.2.0",
|
|
32
|
+
"lint-staged": "16.2.6",
|
|
33
|
+
"prettier": "~2.8.8",
|
|
34
|
+
"react-dom": "^19.2.1",
|
|
35
|
+
"react": "^19.2.1",
|
|
36
|
+
"storybook": "10.1.11",
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vite": "^7.2.2",
|
|
39
|
+
"vitest": "^4.0.10",
|
|
40
|
+
"@purpurds/component-rig": "1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@types/react": "^18 || ^19",
|
|
44
|
+
"@types/react-dom": "^18 || ^19",
|
|
45
|
+
"react": "^18 || ^19",
|
|
46
|
+
"react-dom": "^18 || ^19"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@types/react": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@types/react-dom": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build:dev": "vite",
|
|
58
|
+
"build:watch": "vite build --watch",
|
|
59
|
+
"build": "vite build",
|
|
60
|
+
"ci:build": "rushx build",
|
|
61
|
+
"coverage": "vitest run --coverage",
|
|
62
|
+
"lint:fix": "eslint . --fix",
|
|
63
|
+
"lint": "lint-staged --no-stash 2>&1",
|
|
64
|
+
"sbdev": "rush sbdev",
|
|
65
|
+
"test:unit": "vitest run --passWithNoTests",
|
|
66
|
+
"test:watch": "vitest --watch",
|
|
67
|
+
"test": "rushx test:unit",
|
|
68
|
+
"typecheck": "tsc -p ./tsconfig.json"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
@use "@purpurds/tokens/breakpoint/variables" as *;
|
|
2
|
+
|
|
3
|
+
// Spacing size mappings (base values)
|
|
4
|
+
// xxxs -> spacing-50 (4px)
|
|
5
|
+
// xxs -> spacing-100 (8px)
|
|
6
|
+
// xs -> spacing-200 (16px)
|
|
7
|
+
// sm -> spacing-300 (24px)
|
|
8
|
+
// md -> spacing-400 (32px)
|
|
9
|
+
// lg -> spacing-600 (48px)
|
|
10
|
+
// xl -> spacing-800 (64px)
|
|
11
|
+
// xxl -> spacing-1000 (80px)
|
|
12
|
+
// xxxl -> spacing-1200 (96px)
|
|
13
|
+
|
|
14
|
+
.purpur-spacer {
|
|
15
|
+
// Width sizes
|
|
16
|
+
&--width-xxxs {
|
|
17
|
+
--width-size: var(--purpur-spacing-50);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&--width-xxs {
|
|
21
|
+
--width-size: var(--purpur-spacing-100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&--width-xs {
|
|
25
|
+
--width-size: var(--purpur-spacing-200);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&--width-sm {
|
|
29
|
+
--width-size: var(--purpur-spacing-300);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&--width-md {
|
|
33
|
+
--width-size: var(--purpur-spacing-400);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&--width-lg {
|
|
37
|
+
--width-size: var(--purpur-spacing-600);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&--width-xl {
|
|
41
|
+
--width-size: var(--purpur-spacing-800);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&--width-xxl {
|
|
45
|
+
--width-size: var(--purpur-spacing-1000);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&--width-xxxl {
|
|
49
|
+
--width-size: var(--purpur-spacing-1200);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Height sizes
|
|
53
|
+
&--height-xxxs {
|
|
54
|
+
--height-size: var(--purpur-spacing-50);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&--height-xxs {
|
|
58
|
+
--height-size: var(--purpur-spacing-100);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&--height-xs {
|
|
62
|
+
--height-size: var(--purpur-spacing-200);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&--height-sm {
|
|
66
|
+
--height-size: var(--purpur-spacing-300);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--height-md {
|
|
70
|
+
--height-size: var(--purpur-spacing-400);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&--height-lg {
|
|
74
|
+
--height-size: var(--purpur-spacing-600);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&--height-xl {
|
|
78
|
+
--height-size: var(--purpur-spacing-800);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&--height-xxl {
|
|
82
|
+
--height-size: var(--purpur-spacing-1000);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&--height-xxxl {
|
|
86
|
+
--height-size: var(--purpur-spacing-1200);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Apply dimensions
|
|
90
|
+
width: var(--width-size, 0);
|
|
91
|
+
height: var(--height-size, 0);
|
|
92
|
+
|
|
93
|
+
// Dynamic scaling at breakpoints
|
|
94
|
+
&--dynamic {
|
|
95
|
+
// 1.5x above md breakpoint (600px)
|
|
96
|
+
@media (min-width: $purpur-breakpoint-md) {
|
|
97
|
+
width: calc(var(--width-size, 0) * 1.5);
|
|
98
|
+
height: calc(var(--height-size, 0) * 1.5);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 2.5x above lg breakpoint (1024px)
|
|
102
|
+
@media (min-width: $purpur-breakpoint-lg) {
|
|
103
|
+
width: calc(var(--width-size, 0) * 2.5);
|
|
104
|
+
height: calc(var(--height-size, 0) * 2.5);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Half size modifier - divides dimensions by 2
|
|
109
|
+
&--half {
|
|
110
|
+
width: calc(var(--width-size, 0) / 2);
|
|
111
|
+
height: calc(var(--height-size, 0) / 2);
|
|
112
|
+
|
|
113
|
+
// Half + dynamic scaling
|
|
114
|
+
&.purpur-spacer--dynamic {
|
|
115
|
+
@media (min-width: $purpur-breakpoint-md) {
|
|
116
|
+
width: calc(var(--width-size, 0) / 2 * 1.5);
|
|
117
|
+
height: calc(var(--height-size, 0) / 2 * 1.5);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@media (min-width: $purpur-breakpoint-lg) {
|
|
121
|
+
width: calc(var(--width-size, 0) / 2 * 2.5);
|
|
122
|
+
height: calc(var(--height-size, 0) / 2 * 2.5);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Background colors (for presentation/debugging)
|
|
128
|
+
// Maps sizes to purple color scale
|
|
129
|
+
&--bg-xxxs {
|
|
130
|
+
background-color: var(--purpur-color-purple-50);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&--bg-xxs {
|
|
134
|
+
background-color: var(--purpur-color-purple-100);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&--bg-xs {
|
|
138
|
+
background-color: var(--purpur-color-purple-200);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
&--bg-sm {
|
|
142
|
+
background-color: var(--purpur-color-purple-300);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&--bg-md {
|
|
146
|
+
background-color: var(--purpur-color-purple-400);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
&--bg-lg {
|
|
150
|
+
background-color: var(--purpur-color-purple-500);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
&--bg-xl {
|
|
154
|
+
background-color: var(--purpur-color-purple-600);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&--bg-xxl {
|
|
158
|
+
background-color: var(--purpur-color-purple-700);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
&--bg-xxxl {
|
|
162
|
+
background-color: var(--purpur-color-purple-800);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
3
|
+
|
|
4
|
+
import { Spacer, SPACER_SIZE, type SpacerSize } from "./spacer";
|
|
5
|
+
|
|
6
|
+
/** Mapping of size names to spacing tokens */
|
|
7
|
+
const SIZE_TOKEN_MAP: Record<SpacerSize, string> = {
|
|
8
|
+
xxxs: "spacing-50 (4px)",
|
|
9
|
+
xxs: "spacing-100 (8px)",
|
|
10
|
+
xs: "spacing-200 (16px)",
|
|
11
|
+
sm: "spacing-300 (24px)",
|
|
12
|
+
md: "spacing-400 (32px)",
|
|
13
|
+
lg: "spacing-600 (48px)",
|
|
14
|
+
xl: "spacing-800 (64px)",
|
|
15
|
+
xxl: "spacing-1000 (80px)",
|
|
16
|
+
xxxl: "spacing-1200 (96px)",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: "Utils/Spacer",
|
|
21
|
+
component: Spacer,
|
|
22
|
+
parameters: {
|
|
23
|
+
design: [],
|
|
24
|
+
},
|
|
25
|
+
argTypes: {
|
|
26
|
+
width: {
|
|
27
|
+
control: "select",
|
|
28
|
+
options: [undefined, ...SPACER_SIZE],
|
|
29
|
+
table: { type: { summary: SPACER_SIZE.map((x) => `"${x}"`).join(" | ") } },
|
|
30
|
+
description: "Width spacing size",
|
|
31
|
+
},
|
|
32
|
+
height: {
|
|
33
|
+
control: "select",
|
|
34
|
+
options: [undefined, ...SPACER_SIZE],
|
|
35
|
+
table: { type: { summary: SPACER_SIZE.map((x) => `"${x}"`).join(" | ") } },
|
|
36
|
+
description: "Height spacing size",
|
|
37
|
+
},
|
|
38
|
+
dynamic: {
|
|
39
|
+
control: "boolean",
|
|
40
|
+
description: "Whether the spacer scales with breakpoints (1.5x at md, 2.5x at lg)",
|
|
41
|
+
},
|
|
42
|
+
half: {
|
|
43
|
+
control: "boolean",
|
|
44
|
+
description: "Divide the size in half",
|
|
45
|
+
},
|
|
46
|
+
background: {
|
|
47
|
+
control: "boolean",
|
|
48
|
+
description: "Show background color based on size (purple scale)",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
} satisfies Meta<typeof Spacer>;
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
type Story = StoryObj<typeof meta>;
|
|
55
|
+
|
|
56
|
+
const Box = ({ children }: { children: React.ReactNode }) => (
|
|
57
|
+
<div
|
|
58
|
+
style={{
|
|
59
|
+
backgroundColor: "var(--purpur-color-background-brand-subtle)",
|
|
60
|
+
padding: "var(--purpur-spacing-200)",
|
|
61
|
+
borderRadius: "var(--purpur-border-radius-sm)",
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const AllSizes: Story = {
|
|
69
|
+
args: {
|
|
70
|
+
dynamic: false,
|
|
71
|
+
background: true,
|
|
72
|
+
},
|
|
73
|
+
render: () => (
|
|
74
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "var(--purpur-spacing-200)" }}>
|
|
75
|
+
<h3>Height Sizes</h3>
|
|
76
|
+
{SPACER_SIZE.map((size) => (
|
|
77
|
+
<div key={size} style={{ display: "flex", alignItems: "center" }}>
|
|
78
|
+
<span style={{ width: "10rem", display: "flex", flexDirection: "column" }}>
|
|
79
|
+
<strong>{size}</strong>
|
|
80
|
+
<small>{SIZE_TOKEN_MAP[size]}</small>
|
|
81
|
+
</span>
|
|
82
|
+
<Spacer height={size} background style={{ width: "100%" }} />
|
|
83
|
+
</div>
|
|
84
|
+
))}
|
|
85
|
+
<h3 style={{ marginTop: "var(--purpur-spacing-400)" }}>Width Sizes</h3>
|
|
86
|
+
{SPACER_SIZE.map((size) => (
|
|
87
|
+
<div key={size} style={{ display: "flex", alignItems: "center" }}>
|
|
88
|
+
<span style={{ width: "10rem", display: "flex", flexDirection: "column" }}>
|
|
89
|
+
<strong>{size}</strong>
|
|
90
|
+
<small>{SIZE_TOKEN_MAP[size]}</small>
|
|
91
|
+
</span>
|
|
92
|
+
<Spacer width={size} background style={{ height: "var(--purpur-spacing-200)" }} />
|
|
93
|
+
</div>
|
|
94
|
+
))}
|
|
95
|
+
</div>
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const HorizontalDynamic: Story = {
|
|
100
|
+
args: {
|
|
101
|
+
width: "md",
|
|
102
|
+
dynamic: true,
|
|
103
|
+
background: true,
|
|
104
|
+
},
|
|
105
|
+
render: (args) => (
|
|
106
|
+
<div style={{ display: "flex", alignItems: "center" }}>
|
|
107
|
+
<Box>Left</Box>
|
|
108
|
+
<Spacer {...args} style={{ height: "8px" }} />
|
|
109
|
+
<Box>Right</Box>
|
|
110
|
+
</div>
|
|
111
|
+
),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const VerticalDynamic: Story = {
|
|
115
|
+
args: {
|
|
116
|
+
height: "md",
|
|
117
|
+
dynamic: true,
|
|
118
|
+
background: true,
|
|
119
|
+
},
|
|
120
|
+
render: (args) => (
|
|
121
|
+
<div style={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
|
122
|
+
<Box>Top</Box>
|
|
123
|
+
<Spacer {...args} style={{ width: "100%" }} />
|
|
124
|
+
<Box>Bottom</Box>
|
|
125
|
+
</div>
|
|
126
|
+
),
|
|
127
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
3
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { Spacer } from "./spacer";
|
|
7
|
+
|
|
8
|
+
expect.extend(matchers);
|
|
9
|
+
|
|
10
|
+
describe("Spacer", () => {
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
it("should render with width size class", () => {
|
|
14
|
+
render(<Spacer width="md" data-testid="spacer" />);
|
|
15
|
+
|
|
16
|
+
const spacer = screen.getByTestId("spacer");
|
|
17
|
+
expect(spacer).toHaveClass("purpur-spacer");
|
|
18
|
+
expect(spacer).toHaveClass("purpur-spacer--width-md");
|
|
19
|
+
expect(spacer).not.toHaveClass("purpur-spacer--dynamic");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should render with height size class", () => {
|
|
23
|
+
render(<Spacer height="lg" data-testid="spacer" />);
|
|
24
|
+
|
|
25
|
+
const spacer = screen.getByTestId("spacer");
|
|
26
|
+
expect(spacer).toHaveClass("purpur-spacer");
|
|
27
|
+
expect(spacer).toHaveClass("purpur-spacer--height-lg");
|
|
28
|
+
expect(spacer).not.toHaveClass("purpur-spacer--dynamic");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should render with both width and height sizes", () => {
|
|
32
|
+
render(<Spacer width="sm" height="xl" data-testid="spacer" />);
|
|
33
|
+
|
|
34
|
+
const spacer = screen.getByTestId("spacer");
|
|
35
|
+
expect(spacer).toHaveClass("purpur-spacer--width-sm");
|
|
36
|
+
expect(spacer).toHaveClass("purpur-spacer--height-xl");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should not have dynamic class when dynamic is false", () => {
|
|
40
|
+
render(<Spacer height="md" dynamic={false} data-testid="spacer" />);
|
|
41
|
+
|
|
42
|
+
const spacer = screen.getByTestId("spacer");
|
|
43
|
+
expect(spacer).toHaveClass("purpur-spacer");
|
|
44
|
+
expect(spacer).toHaveClass("purpur-spacer--height-md");
|
|
45
|
+
expect(spacer).not.toHaveClass("purpur-spacer--dynamic");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should not be dynamic by default", () => {
|
|
49
|
+
render(<Spacer height="md" data-testid="spacer" />);
|
|
50
|
+
|
|
51
|
+
const spacer = screen.getByTestId("spacer");
|
|
52
|
+
expect(spacer).not.toHaveClass("purpur-spacer--dynamic");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should be extendable for styling, also keep existing", () => {
|
|
56
|
+
render(<Spacer width="xs" className="custom-styling" data-testid="spacer" />);
|
|
57
|
+
|
|
58
|
+
const spacer = screen.getByTestId("spacer");
|
|
59
|
+
expect(spacer).toHaveClass("purpur-spacer");
|
|
60
|
+
expect(spacer).toHaveClass("purpur-spacer--width-xs");
|
|
61
|
+
expect(spacer).toHaveClass("custom-styling");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should pass through "data-" & accessibility attributes', () => {
|
|
65
|
+
render(
|
|
66
|
+
<Spacer height="sm" data-testid="spacer" data-test-id="other-convention" aria-hidden="true" />
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const spacer = screen.getByTestId("spacer");
|
|
70
|
+
expect(spacer).toHaveAttribute("data-test-id", "other-convention");
|
|
71
|
+
expect(spacer).toHaveAttribute("aria-hidden", "true");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should support all size values for width prop", () => {
|
|
75
|
+
const sizes = ["xxxs", "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"] as const;
|
|
76
|
+
|
|
77
|
+
sizes.forEach((size) => {
|
|
78
|
+
const { unmount } = render(<Spacer width={size} data-testid="spacer" />);
|
|
79
|
+
const spacer = screen.getByTestId("spacer");
|
|
80
|
+
expect(spacer).toHaveClass(`purpur-spacer--width-${size}`);
|
|
81
|
+
unmount();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should support all size values for height prop", () => {
|
|
86
|
+
const sizes = ["xxxs", "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"] as const;
|
|
87
|
+
|
|
88
|
+
sizes.forEach((size) => {
|
|
89
|
+
const { unmount } = render(<Spacer height={size} data-testid="spacer" />);
|
|
90
|
+
const spacer = screen.getByTestId("spacer");
|
|
91
|
+
expect(spacer).toHaveClass(`purpur-spacer--height-${size}`);
|
|
92
|
+
unmount();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should apply debug class when background is true with width prop", () => {
|
|
97
|
+
render(<Spacer width="md" background data-testid="spacer" />);
|
|
98
|
+
|
|
99
|
+
const spacer = screen.getByTestId("spacer");
|
|
100
|
+
expect(spacer).toHaveClass("purpur-spacer--bg-md");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should apply debug class when background is true with height prop", () => {
|
|
104
|
+
render(<Spacer height="lg" background data-testid="spacer" />);
|
|
105
|
+
|
|
106
|
+
const spacer = screen.getByTestId("spacer");
|
|
107
|
+
expect(spacer).toHaveClass("purpur-spacer--bg-lg");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should not apply debug class when background is false", () => {
|
|
111
|
+
render(<Spacer height="md" background={false} data-testid="spacer" />);
|
|
112
|
+
|
|
113
|
+
const spacer = screen.getByTestId("spacer");
|
|
114
|
+
expect(spacer).not.toHaveClass("purpur-spacer--bg-md");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should not apply debug class when background is not provided", () => {
|
|
118
|
+
render(<Spacer height="md" data-testid="spacer" />);
|
|
119
|
+
|
|
120
|
+
const spacer = screen.getByTestId("spacer");
|
|
121
|
+
expect(spacer).not.toHaveClass("purpur-spacer--bg-md");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should use width prop for debug class when both width and height are provided", () => {
|
|
125
|
+
render(<Spacer width="sm" height="lg" background data-testid="spacer" />);
|
|
126
|
+
|
|
127
|
+
const spacer = screen.getByTestId("spacer");
|
|
128
|
+
expect(spacer).toHaveClass("purpur-spacer--bg-sm");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should apply half class when half is true", () => {
|
|
132
|
+
render(<Spacer height="md" half data-testid="spacer" />);
|
|
133
|
+
|
|
134
|
+
const spacer = screen.getByTestId("spacer");
|
|
135
|
+
expect(spacer).toHaveClass("purpur-spacer--half");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should not apply half class when half is false", () => {
|
|
139
|
+
render(<Spacer height="md" half={false} data-testid="spacer" />);
|
|
140
|
+
|
|
141
|
+
const spacer = screen.getByTestId("spacer");
|
|
142
|
+
expect(spacer).not.toHaveClass("purpur-spacer--half");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("should combine half with dynamic", () => {
|
|
146
|
+
render(<Spacer height="md" half dynamic data-testid="spacer" />);
|
|
147
|
+
|
|
148
|
+
const spacer = screen.getByTestId("spacer");
|
|
149
|
+
expect(spacer).toHaveClass("purpur-spacer--half");
|
|
150
|
+
expect(spacer).toHaveClass("purpur-spacer--dynamic");
|
|
151
|
+
});
|
|
152
|
+
});
|
package/src/spacer.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { BaseProps } from "@purpurds/common-types";
|
|
3
|
+
import c from "classnames/bind";
|
|
4
|
+
|
|
5
|
+
import styles from "./spacer.module.scss";
|
|
6
|
+
|
|
7
|
+
const cx = c.bind(styles);
|
|
8
|
+
const rootClassName = "purpur-spacer";
|
|
9
|
+
|
|
10
|
+
export const SPACER_SIZE = ["xxxs", "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"] as const;
|
|
11
|
+
|
|
12
|
+
export type SpacerSize = (typeof SPACER_SIZE)[number];
|
|
13
|
+
|
|
14
|
+
export type SpacerProps = Omit<BaseProps, "children"> & {
|
|
15
|
+
/** Width spacing size (horizontal) */
|
|
16
|
+
width?: SpacerSize;
|
|
17
|
+
/** Height spacing size (vertical) */
|
|
18
|
+
height?: SpacerSize;
|
|
19
|
+
/** Whether the spacer scales with breakpoints. Default is true (dynamic). */
|
|
20
|
+
dynamic?: boolean;
|
|
21
|
+
/** Divide the size in half */
|
|
22
|
+
half?: boolean;
|
|
23
|
+
/** Show background color based on size (for presentation/debugging) */
|
|
24
|
+
background?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Spacer = ({
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
dynamic = false,
|
|
31
|
+
half,
|
|
32
|
+
background,
|
|
33
|
+
className,
|
|
34
|
+
...props
|
|
35
|
+
}: SpacerProps) => (
|
|
36
|
+
<div
|
|
37
|
+
{...props}
|
|
38
|
+
className={cx(className, rootClassName, {
|
|
39
|
+
[`${rootClassName}--width-${width}`]: width,
|
|
40
|
+
[`${rootClassName}--height-${height}`]: height,
|
|
41
|
+
[`${rootClassName}--dynamic`]: dynamic,
|
|
42
|
+
[`${rootClassName}--half`]: half,
|
|
43
|
+
[`${rootClassName}--bg-${width || height}`]: background && (width || height),
|
|
44
|
+
})}
|
|
45
|
+
/>
|
|
46
|
+
);
|