ali-mohammadi-design-system 2.0.3 → 2.0.6
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/index.cjs +17 -17
- package/dist/index.js +190 -124
- package/package.json +5 -2
- package/src/components/Button/Button.jsx +28 -18
- package/src/index.js +3 -0
- package/src/utils/index.js +2 -0
- package/src/utils/muiHelpers.js +88 -0
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
2
|
-
`;Object.entries(
|
|
3
|
-
`})});const
|
|
4
|
-
`,
|
|
5
|
-
`}else e+=` --font-size-base: ${
|
|
6
|
-
`;e+=` --type-scale: ${
|
|
7
|
-
`,
|
|
8
|
-
`}),
|
|
9
|
-
`}),
|
|
10
|
-
`});const
|
|
11
|
-
`,Object.entries(
|
|
12
|
-
`)}),Object.entries(
|
|
13
|
-
`}),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C=require("react/jsx-runtime"),p=require("react"),u=require("prop-types"),g={neutral:{0:"#FFFFFF",50:"#FAFAFA"},primary:{50:"#e3f2fd",500:"#2196f3"}},k={Neutral:{0:"#FFFFFF",50:"#FAFAFA",100:"#F4F4F5",200:"#EAEAEB",300:"#D4D5D6",400:"#AAABAD",500:"#7F8185",600:"#55575C",700:"#2A2D33",800:"#232529",900:"#1B1D21"},Purple:{100:"#F9F2FD",200:"#E6D9EC",300:"#D9C5E2",400:"#B38CC5",500:"#9A65B2",600:"#813F9F",700:"#67327F",800:"#4D265F",900:"#341940"},Blue:{100:"#E5EDFB",200:"#CCDAF7",300:"#B2C8F3",400:"#99B5EF",500:"#6691E8",600:"#336CE0",700:"#0047D8",800:"#0039AD",900:"#002B82"},Violet:{100:"#EDECFC",200:"#DCDAFA",300:"#CAC7F7",400:"#B9B5F5",500:"#9690EF",600:"#736BEA",700:"#5046E5",800:"#4038B8",900:"#191547",950:"#110E30"},Yellow:{100:"#FEF8E9",200:"#FDF1D3",300:"#FCEABD",400:"#FBE3A7",500:"#FAD67C",600:"#F8C850",700:"#F6BA24",800:"#ECAD11",900:"#CE960A"},Red:{100:"#FFEBEB",200:"#FFD6D6",300:"#FFC2C2",400:"#FFADAD",500:"#FF8585",600:"#FF5C5C",700:"#FF3333",800:"#CE2929",900:"#9D1F1F"},Green:{100:"#EBFAF1",200:"#D7F4E4",300:"#AFE9C8",400:"#87DFAD",500:"#5FD491",600:"#5FD491",700:"#2CA15E",800:"#217947",900:"#16502F"},Orange:{100:"#FFF4EB",200:"#FFE9D6",300:"#FFDEC2",400:"#FFD3AE",500:"#FFBD85",600:"#FFA75D",700:"#FF9134",800:"#E8842F",900:"#DF771E"},Cyan:{100:"#E8F6FF",200:"#DCF2FF",300:"#C4E9FF",400:"#A0DAFF",500:"#87D1FF",600:"#56BFFF",700:"#1DA6FB",800:"#0B89D6",900:"#0467A4"},TypeScale:{Weight:{Regular:"Regular",Bold:"Bold",SemiBold:"Semibold"},FontFamily:{YekanBakh:"Yekan Bakh FaNum"},Size:{10:10,11:11,12:12,14:14,16:16,18:18,20:20,24:24,28:28,32:32,36:36,48:48,64:64},Height:{10:10,12:12,14:14,16:16,20:20,24:24,28:28,32:32,36:36,40:40,44:44,48:48,74:74}},NumberScale:{Radius:{"Radius-12":12,"Radius-8":8,"Radius-4":4,"Radius-24":24,"Radius-20":20,"Radius-16":16,"Radius-Full":1e3,"Radius-28":28},Spacing:{"spacing-4":4,"spacing-8":8,"spacing-12":12,"spacing-16":16,"spacing-20":20,"spacing-24":24,"spacing-32":32,"spacing-40":40,"spacing-48":48,"spacing-56":56,"spacing-64":64,"spacing-72":72,"spacing-80":80},StrokeWeight:{StrokeWeight1:1,StrokeWeight2:1.5,StrokeWeight4:3,StrokeWeight3:2,StrokeWeight5:4},IconSize:{IconSizesmall:16,IconSizeMedium:20,IconSizeLarge:24,IconSizeExtraLarge:32}},Peach:{100:"#FFEEE5",200:"#FFDDCC",300:"#FFCCB2",400:"#FFBB99",500:"#FF9966",600:"#FF7733",700:"#FF5500",800:"#CC4400",900:"#993300"},Buttons:104,MinWidth:64},l={brand:k};function j(){const r={colors:{},typography:{},spacing:{},radius:{},shadows:{}};if(l.brand&&Object.entries(l.brand).forEach(([t,n])=>{if(typeof n=="object"&&!Array.isArray(n)){const e=t.toLowerCase();r.colors[e]={},Object.entries(n).forEach(([o,c])=>{(typeof c=="string"||typeof c=="number")&&(r.colors[e][o]=c)})}}),l.brand?.TypeScale){const t=l.brand.TypeScale;r.typography={fontFamily:t.FontFamily?.YekanBakh,sizes:t.Size||{},lineHeights:t.Height||{},weights:t.Weight||{}}}if(l.brand?.NumberScale){const t=l.brand.NumberScale;t.Spacing&&(r.spacing={},Object.entries(t.Spacing).forEach(([n,e])=>{const o=n.replace("spacing-","");r.spacing[o]=typeof e=="number"?e:parseInt(e)})),t.Radius&&(r.radius={},Object.entries(t.Radius).forEach(([n,e])=>{const o=n.replace("Radius-","").toLowerCase();r.radius[o]=typeof e=="number"?e:parseInt(e)}))}return r}const S={colors:{primary:{50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1"},neutral:{0:"#FFFFFF",50:"#FAFAFA",100:"#F5F5F5",200:"#EEEEEE",300:"#E0E0E0",400:"#BDBDBD",500:"#9E9E9E",600:"#757575",700:"#616161",800:"#424242",900:"#212121"},success:{50:"#e8f5e9",100:"#c8e6c9",200:"#a5d6a7",300:"#81c784",400:"#66bb6a",500:"#4caf50",600:"#43a047",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"},error:{50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",900:"#b71c1c"},warning:{50:"#fff3e0",100:"#ffe0b2",200:"#ffcc80",300:"#ffb74d",400:"#ffa726",500:"#ff9800",600:"#fb8c00",700:"#f57c00",800:"#ef6c00",900:"#e65100"},info:{50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1"}},typography:{fontFamily:"system-ui, -apple-system, sans-serif",baseSize:16,minSize:14,scaleRatio:1.25,sizes:{10:10,11:11,12:12,14:14,16:16,18:18,20:20,24:24,28:28,32:32,36:36,48:48,64:64},lineHeights:{10:10,12:12,14:14,16:16,20:20,24:24,28:28,32:32,36:36,40:40,44:44,48:48,74:74},weights:{regular:"400",semibold:"600",bold:"700"}},spacing:{unit:4,4:4,8:8,12:12,16:16,20:20,24:24,32:32,40:40,48:48,56:56,64:64,72:72,80:80},radius:{xs:4,sm:8,md:12,lg:16,xl:20,"2xl":24,"3xl":28,full:1e3},shadows:{sm:"0px 1px 2px rgba(0, 0, 0, 0.05)",md:"0px 4px 6px rgba(0, 0, 0, 0.1)",lg:"0px 10px 15px rgba(0, 0, 0, 0.1)",xl:"0px 20px 25px rgba(0, 0, 0, 0.1)"}};function b(r,t){const n={...r};return m(r)&&m(t)&&Object.keys(t).forEach(e=>{m(t[e])?e in r?n[e]=b(r[e],t[e]):Object.assign(n,{[e]:t[e]}):Object.assign(n,{[e]:t[e]})}),n}function m(r){return r&&typeof r=="object"&&!Array.isArray(r)}const w=j(),d=b(S,w);function y(r={}){return b(d,r)}function h(r={}){const t=y(r),n=document.createElement("style");n.id="ds-theme";let e=`:root {
|
|
2
|
+
`;Object.entries(t.colors).forEach(([s,a])=>{typeof a=="object"&&Object.entries(a).forEach(([f,F])=>{e+=` --${s}-${f}: ${F};
|
|
3
|
+
`})});const o=t.typography;if(e+=` --font-family: ${o.fontFamily};
|
|
4
|
+
`,o.baseSize&&o.minSize){const s=(o.baseSize-o.minSize)/1600,f=`${-320*s+o.minSize}px + ${s*100}vw`;e+=` --font-size-base: clamp(${o.minSize}px, ${f}, ${o.baseSize}px);
|
|
5
|
+
`}else e+=` --font-size-base: ${o.baseSize||16}px;
|
|
6
|
+
`;e+=` --type-scale: ${o.scaleRatio||1.25};
|
|
7
|
+
`,o.sizes&&Object.entries(o.sizes).forEach(([s,a])=>{e+=` --font-size-${s}: ${a}px;
|
|
8
|
+
`}),o.lineHeights&&Object.entries(o.lineHeights).forEach(([s,a])=>{e+=` --line-height-${s}: ${a}px;
|
|
9
|
+
`}),o.weights&&Object.entries(o.weights).forEach(([s,a])=>{e+=` --font-weight-${s}: ${a};
|
|
10
|
+
`});const c=t.spacing.unit||4;e+=` --space-unit: ${c}px;
|
|
11
|
+
`,Object.entries(t.spacing).forEach(([s,a])=>{s!=="unit"&&(e+=` --space-${s}: ${a}px;
|
|
12
|
+
`)}),Object.entries(t.radius).forEach(([s,a])=>{e+=` --radius-${s}: ${a}px;
|
|
13
|
+
`}),t.shadows&&Object.entries(t.shadows).forEach(([s,a])=>{e+=` --shadow-${s}: ${a};
|
|
14
14
|
`}),e+=`}
|
|
15
15
|
`,e+=`html { font-size: var(--font-size-base); }
|
|
16
16
|
`,e+=`body { font-family: var(--font-family); }
|
|
17
|
-
`,
|
|
18
|
-
`}),
|
|
19
|
-
`,
|
|
20
|
-
`,
|
|
17
|
+
`,n.textContent=e;const i=document.getElementById("ds-theme");i&&i.remove(),document.head.appendChild(n)}const $=p.createContext(null);function E({tokens:r={},children:t}){const n=p.useMemo(()=>y(r),[r]);p.useEffect(()=>{h(n)},[n]);const e=p.useMemo(()=>({tokens:n,getToken:o=>{const c=o.split(".");let i=n;for(const s of c)if(i&&typeof i=="object"&&s in i)i=i[s];else return;return i}}),[n]);return C.jsx($.Provider,{value:e,children:t})}E.propTypes={tokens:u.object,children:u.node.isRequired};function x(){const r=p.useContext($);return r||(console.warn("useTheme must be used within ThemeProvider. Using default tokens."),{tokens:d,getToken:t=>{const n=t.split(".");let e=d;for(const o of n)if(e&&typeof e=="object"&&o in e)e=e[o];else return;return e}})}function B(){const{tokens:r,getToken:t}=x();return{color:n=>{const e=t(`colors.${n}`);if(e)return e;const[o,c]=n.split(".");return`var(--${o}-${c}, #000)`},spacing:n=>{const e=t(`spacing.${n}`);return e?`${e}px`:`var(--space-${n}, ${n*(r.spacing?.unit||4)}px)`},radius:n=>{const e=t(`radius.${n}`);return e?`${e}px`:`var(--radius-${n}, 8px)`},typography:n=>{const e=t(`typography.${n}`);return e?typeof e=="number"?`${e}px`:e:n==="fontFamily"?"var(--font-family, system-ui, sans-serif)":`var(--font-${n}, 16px)`},shadow:n=>{const e=t(`shadows.${n}`);return e||`var(--shadow-${n}, none)`},tokens:r,getToken:t}}function v(){try{const{transitions:r}=require("@mui/material/styles");return r}catch{throw new Error("@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید.")}}function O(){try{const{useTheme:r}=require("@mui/material/styles");return r}catch{throw new Error("@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید.")}}function R(){try{return require("@emotion/styled")}catch{throw new Error("@emotion/styled باید در پروژه نصب شود. لطفاً npm install @emotion/styled را اجرا کنید.")}}function I(){try{const{Box:r}=require("@mui/material");return r}catch{throw new Error("@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید.")}}function D(){try{const{ButtonBase:r}=require("@mui/material");return r}catch{throw new Error("@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید.")}}const A=({variant:r="primary",size:t="md",children:n,className:e="",sx:o,...c})=>{const{color:i,spacing:s,radius:a,typography:f}=B(),F=D(),z={primary:{backgroundColor:i("primary.500"),color:"#ffffff",border:"none","&:hover":{backgroundColor:i("primary.600")}},outline:{backgroundColor:"transparent",border:`2px solid ${i("primary.500")}`,color:i("primary.500"),"&:hover":{backgroundColor:i("primary.50")}},text:{backgroundColor:"transparent",border:"none",color:i("primary.500"),"&:hover":{backgroundColor:i("primary.50")}},secondary:{backgroundColor:i("neutral.200"),color:i("neutral.900"),border:"none","&:hover":{backgroundColor:i("neutral.300")}},success:{backgroundColor:i("success.500"),color:"#ffffff",border:"none","&:hover":{backgroundColor:i("success.600")}},error:{backgroundColor:i("error.500"),color:"#ffffff",border:"none","&:hover":{backgroundColor:i("error.600")}}},T={sm:{padding:`${s(2)} ${s(4)}`,fontSize:f("sizes.14")||"14px"},md:{padding:`${s(3)} ${s(6)}`,fontSize:f("sizes.16")||"16px"},lg:{padding:`${s(4)} ${s(8)}`,fontSize:f("sizes.18")||"18px"}};return C.jsx(F,{className:`ds-button ds-button--${r} ds-button--${t} ${e}`,sx:{borderRadius:a("md"),fontFamily:f("fontFamily"),fontWeight:"500",cursor:"pointer",...z[r],...T[t],...o},...c,children:n})};A.propTypes={children:u.node.isRequired,variant:u.oneOf(["primary","outline","text","secondary","success","error"]),size:u.oneOf(["sm","md","lg"]),className:u.string,sx:u.object};function M(r={}){h(r)}const U={};function q(r={}){let t="";Object.entries(r.colors?.primary||{}).forEach(([n,e])=>{t+=`$primary-${n}: ${e};
|
|
18
|
+
`}),t+=`$font-family: "${r.typography?.fontFamily||"sans-serif"}";
|
|
19
|
+
`,t+=`$font-size-base: ${r.typography?.baseSize||16}px;
|
|
20
|
+
`,U.writeFileSync("custom-variables.scss",t)}const W={colors:{primary:g.primary,neutral:g.neutral},spacing:{unit:4},typography:{fontFamily:"system-ui, sans-serif",baseSize:16}};exports.Button=A;exports.ThemeProvider=E;exports.baseTokens=d;exports.createTokens=y;exports.default=E;exports.defaultColors=g;exports.defaultConfig=W;exports.defaultTokens=S;exports.generateSCSS=q;exports.generateTheme=h;exports.getMUIBox=I;exports.getMUIButtonBase=D;exports.getMUIStyled=R;exports.getMUITheme=O;exports.getMUITransitions=v;exports.injectCSS=M;exports.useTheme=x;exports.useTokens=B;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as S, useMemo as
|
|
3
|
-
import
|
|
4
|
-
const
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as S, useMemo as g, useEffect as B, useContext as D } from "react";
|
|
3
|
+
import l from "prop-types";
|
|
4
|
+
const b = {
|
|
5
5
|
neutral: {
|
|
6
6
|
0: "#FFFFFF",
|
|
7
7
|
50: "#FAFAFA"
|
|
@@ -10,7 +10,7 @@ const y = {
|
|
|
10
10
|
50: "#e3f2fd",
|
|
11
11
|
500: "#2196f3"
|
|
12
12
|
}
|
|
13
|
-
}, A = { Neutral: { 0: "#FFFFFF", 50: "#FAFAFA", 100: "#F4F4F5", 200: "#EAEAEB", 300: "#D4D5D6", 400: "#AAABAD", 500: "#7F8185", 600: "#55575C", 700: "#2A2D33", 800: "#232529", 900: "#1B1D21" }, Purple: { 100: "#F9F2FD", 200: "#E6D9EC", 300: "#D9C5E2", 400: "#B38CC5", 500: "#9A65B2", 600: "#813F9F", 700: "#67327F", 800: "#4D265F", 900: "#341940" }, Blue: { 100: "#E5EDFB", 200: "#CCDAF7", 300: "#B2C8F3", 400: "#99B5EF", 500: "#6691E8", 600: "#336CE0", 700: "#0047D8", 800: "#0039AD", 900: "#002B82" }, Violet: { 100: "#EDECFC", 200: "#DCDAFA", 300: "#CAC7F7", 400: "#B9B5F5", 500: "#9690EF", 600: "#736BEA", 700: "#5046E5", 800: "#4038B8", 900: "#191547", 950: "#110E30" }, Yellow: { 100: "#FEF8E9", 200: "#FDF1D3", 300: "#FCEABD", 400: "#FBE3A7", 500: "#FAD67C", 600: "#F8C850", 700: "#F6BA24", 800: "#ECAD11", 900: "#CE960A" }, Red: { 100: "#FFEBEB", 200: "#FFD6D6", 300: "#FFC2C2", 400: "#FFADAD", 500: "#FF8585", 600: "#FF5C5C", 700: "#FF3333", 800: "#CE2929", 900: "#9D1F1F" }, Green: { 100: "#EBFAF1", 200: "#D7F4E4", 300: "#AFE9C8", 400: "#87DFAD", 500: "#5FD491", 600: "#5FD491", 700: "#2CA15E", 800: "#217947", 900: "#16502F" }, Orange: { 100: "#FFF4EB", 200: "#FFE9D6", 300: "#FFDEC2", 400: "#FFD3AE", 500: "#FFBD85", 600: "#FFA75D", 700: "#FF9134", 800: "#E8842F", 900: "#DF771E" }, Cyan: { 100: "#E8F6FF", 200: "#DCF2FF", 300: "#C4E9FF", 400: "#A0DAFF", 500: "#87D1FF", 600: "#56BFFF", 700: "#1DA6FB", 800: "#0B89D6", 900: "#0467A4" }, TypeScale: { Weight: { Regular: "Regular", Bold: "Bold", SemiBold: "Semibold" }, FontFamily: { YekanBakh: "Yekan Bakh FaNum" }, Size: { 10: 10, 11: 11, 12: 12, 14: 14, 16: 16, 18: 18, 20: 20, 24: 24, 28: 28, 32: 32, 36: 36, 48: 48, 64: 64 }, Height: { 10: 10, 12: 12, 14: 14, 16: 16, 20: 20, 24: 24, 28: 28, 32: 32, 36: 36, 40: 40, 44: 44, 48: 48, 74: 74 } }, NumberScale: { Radius: { "Radius-12": 12, "Radius-8": 8, "Radius-4": 4, "Radius-24": 24, "Radius-20": 20, "Radius-16": 16, "Radius-Full": 1e3, "Radius-28": 28 }, Spacing: { "spacing-4": 4, "spacing-8": 8, "spacing-12": 12, "spacing-16": 16, "spacing-20": 20, "spacing-24": 24, "spacing-32": 32, "spacing-40": 40, "spacing-48": 48, "spacing-56": 56, "spacing-64": 64, "spacing-72": 72, "spacing-80": 80 }, StrokeWeight: { StrokeWeight1: 1, StrokeWeight2: 1.5, StrokeWeight4: 3, StrokeWeight3: 2, StrokeWeight5: 4 }, IconSize: { IconSizesmall: 16, IconSizeMedium: 20, IconSizeLarge: 24, IconSizeExtraLarge: 32 } }, Peach: { 100: "#FFEEE5", 200: "#FFDDCC", 300: "#FFCCB2", 400: "#FFBB99", 500: "#FF9966", 600: "#FF7733", 700: "#FF5500", 800: "#CC4400", 900: "#993300" }, Buttons: 104, MinWidth: 64 },
|
|
13
|
+
}, A = { Neutral: { 0: "#FFFFFF", 50: "#FAFAFA", 100: "#F4F4F5", 200: "#EAEAEB", 300: "#D4D5D6", 400: "#AAABAD", 500: "#7F8185", 600: "#55575C", 700: "#2A2D33", 800: "#232529", 900: "#1B1D21" }, Purple: { 100: "#F9F2FD", 200: "#E6D9EC", 300: "#D9C5E2", 400: "#B38CC5", 500: "#9A65B2", 600: "#813F9F", 700: "#67327F", 800: "#4D265F", 900: "#341940" }, Blue: { 100: "#E5EDFB", 200: "#CCDAF7", 300: "#B2C8F3", 400: "#99B5EF", 500: "#6691E8", 600: "#336CE0", 700: "#0047D8", 800: "#0039AD", 900: "#002B82" }, Violet: { 100: "#EDECFC", 200: "#DCDAFA", 300: "#CAC7F7", 400: "#B9B5F5", 500: "#9690EF", 600: "#736BEA", 700: "#5046E5", 800: "#4038B8", 900: "#191547", 950: "#110E30" }, Yellow: { 100: "#FEF8E9", 200: "#FDF1D3", 300: "#FCEABD", 400: "#FBE3A7", 500: "#FAD67C", 600: "#F8C850", 700: "#F6BA24", 800: "#ECAD11", 900: "#CE960A" }, Red: { 100: "#FFEBEB", 200: "#FFD6D6", 300: "#FFC2C2", 400: "#FFADAD", 500: "#FF8585", 600: "#FF5C5C", 700: "#FF3333", 800: "#CE2929", 900: "#9D1F1F" }, Green: { 100: "#EBFAF1", 200: "#D7F4E4", 300: "#AFE9C8", 400: "#87DFAD", 500: "#5FD491", 600: "#5FD491", 700: "#2CA15E", 800: "#217947", 900: "#16502F" }, Orange: { 100: "#FFF4EB", 200: "#FFE9D6", 300: "#FFDEC2", 400: "#FFD3AE", 500: "#FFBD85", 600: "#FFA75D", 700: "#FF9134", 800: "#E8842F", 900: "#DF771E" }, Cyan: { 100: "#E8F6FF", 200: "#DCF2FF", 300: "#C4E9FF", 400: "#A0DAFF", 500: "#87D1FF", 600: "#56BFFF", 700: "#1DA6FB", 800: "#0B89D6", 900: "#0467A4" }, TypeScale: { Weight: { Regular: "Regular", Bold: "Bold", SemiBold: "Semibold" }, FontFamily: { YekanBakh: "Yekan Bakh FaNum" }, Size: { 10: 10, 11: 11, 12: 12, 14: 14, 16: 16, 18: 18, 20: 20, 24: 24, 28: 28, 32: 32, 36: 36, 48: 48, 64: 64 }, Height: { 10: 10, 12: 12, 14: 14, 16: 16, 20: 20, 24: 24, 28: 28, 32: 32, 36: 36, 40: 40, 44: 44, 48: 48, 74: 74 } }, NumberScale: { Radius: { "Radius-12": 12, "Radius-8": 8, "Radius-4": 4, "Radius-24": 24, "Radius-20": 20, "Radius-16": 16, "Radius-Full": 1e3, "Radius-28": 28 }, Spacing: { "spacing-4": 4, "spacing-8": 8, "spacing-12": 12, "spacing-16": 16, "spacing-20": 20, "spacing-24": 24, "spacing-32": 32, "spacing-40": 40, "spacing-48": 48, "spacing-56": 56, "spacing-64": 64, "spacing-72": 72, "spacing-80": 80 }, StrokeWeight: { StrokeWeight1: 1, StrokeWeight2: 1.5, StrokeWeight4: 3, StrokeWeight3: 2, StrokeWeight5: 4 }, IconSize: { IconSizesmall: 16, IconSizeMedium: 20, IconSizeLarge: 24, IconSizeExtraLarge: 32 } }, Peach: { 100: "#FFEEE5", 200: "#FFDDCC", 300: "#FFCCB2", 400: "#FFBB99", 500: "#FF9966", 600: "#FF7733", 700: "#FF5500", 800: "#CC4400", 900: "#993300" }, Buttons: 104, MinWidth: 64 }, u = {
|
|
14
14
|
brand: A
|
|
15
15
|
};
|
|
16
16
|
function z() {
|
|
@@ -21,15 +21,15 @@ function z() {
|
|
|
21
21
|
radius: {},
|
|
22
22
|
shadows: {}
|
|
23
23
|
};
|
|
24
|
-
if (
|
|
24
|
+
if (u.brand && Object.entries(u.brand).forEach(([n, t]) => {
|
|
25
25
|
if (typeof t == "object" && !Array.isArray(t)) {
|
|
26
26
|
const e = n.toLowerCase();
|
|
27
|
-
r.colors[e] = {}, Object.entries(t).forEach(([o,
|
|
28
|
-
(typeof
|
|
27
|
+
r.colors[e] = {}, Object.entries(t).forEach(([o, c]) => {
|
|
28
|
+
(typeof c == "string" || typeof c == "number") && (r.colors[e][o] = c);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
}),
|
|
32
|
-
const n =
|
|
31
|
+
}), u.brand?.TypeScale) {
|
|
32
|
+
const n = u.brand.TypeScale;
|
|
33
33
|
r.typography = {
|
|
34
34
|
fontFamily: n.FontFamily?.YekanBakh,
|
|
35
35
|
sizes: n.Size || {},
|
|
@@ -37,8 +37,8 @@ function z() {
|
|
|
37
37
|
weights: n.Weight || {}
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
41
|
-
const n =
|
|
40
|
+
if (u.brand?.NumberScale) {
|
|
41
|
+
const n = u.brand.NumberScale;
|
|
42
42
|
n.Spacing && (r.spacing = {}, Object.entries(n.Spacing).forEach(([t, e]) => {
|
|
43
43
|
const o = t.replace("spacing-", "");
|
|
44
44
|
r.spacing[o] = typeof e == "number" ? e : parseInt(e);
|
|
@@ -49,7 +49,7 @@ function z() {
|
|
|
49
49
|
}
|
|
50
50
|
return r;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
52
|
+
const w = {
|
|
53
53
|
colors: {
|
|
54
54
|
primary: {
|
|
55
55
|
50: "#e3f2fd",
|
|
@@ -201,98 +201,98 @@ const B = {
|
|
|
201
201
|
};
|
|
202
202
|
function m(r, n) {
|
|
203
203
|
const t = { ...r };
|
|
204
|
-
return
|
|
205
|
-
|
|
204
|
+
return F(r) && F(n) && Object.keys(n).forEach((e) => {
|
|
205
|
+
F(n[e]) ? e in r ? t[e] = m(r[e], n[e]) : Object.assign(t, { [e]: n[e] }) : Object.assign(t, { [e]: n[e] });
|
|
206
206
|
}), t;
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function F(r) {
|
|
209
209
|
return r && typeof r == "object" && !Array.isArray(r);
|
|
210
210
|
}
|
|
211
|
-
const
|
|
211
|
+
const k = z(), d = m(w, k);
|
|
212
212
|
function h(r = {}) {
|
|
213
|
-
return m(
|
|
213
|
+
return m(d, r);
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function E(r = {}) {
|
|
216
216
|
const n = h(r), t = document.createElement("style");
|
|
217
217
|
t.id = "ds-theme";
|
|
218
218
|
let e = `:root {
|
|
219
219
|
`;
|
|
220
|
-
Object.entries(n.colors).forEach(([s,
|
|
221
|
-
typeof
|
|
222
|
-
e += ` --${s}-${
|
|
220
|
+
Object.entries(n.colors).forEach(([s, a]) => {
|
|
221
|
+
typeof a == "object" && Object.entries(a).forEach(([f, p]) => {
|
|
222
|
+
e += ` --${s}-${f}: ${p};
|
|
223
223
|
`;
|
|
224
224
|
});
|
|
225
225
|
});
|
|
226
226
|
const o = n.typography;
|
|
227
227
|
if (e += ` --font-family: ${o.fontFamily};
|
|
228
228
|
`, o.baseSize && o.minSize) {
|
|
229
|
-
const s = (o.baseSize - o.minSize) / 1600,
|
|
230
|
-
e += ` --font-size-base: clamp(${o.minSize}px, ${
|
|
229
|
+
const s = (o.baseSize - o.minSize) / 1600, f = `${-320 * s + o.minSize}px + ${s * 100}vw`;
|
|
230
|
+
e += ` --font-size-base: clamp(${o.minSize}px, ${f}, ${o.baseSize}px);
|
|
231
231
|
`;
|
|
232
232
|
} else
|
|
233
233
|
e += ` --font-size-base: ${o.baseSize || 16}px;
|
|
234
234
|
`;
|
|
235
235
|
e += ` --type-scale: ${o.scaleRatio || 1.25};
|
|
236
|
-
`, o.sizes && Object.entries(o.sizes).forEach(([s,
|
|
237
|
-
e += ` --font-size-${s}: ${
|
|
236
|
+
`, o.sizes && Object.entries(o.sizes).forEach(([s, a]) => {
|
|
237
|
+
e += ` --font-size-${s}: ${a}px;
|
|
238
238
|
`;
|
|
239
|
-
}), o.lineHeights && Object.entries(o.lineHeights).forEach(([s,
|
|
240
|
-
e += ` --line-height-${s}: ${
|
|
239
|
+
}), o.lineHeights && Object.entries(o.lineHeights).forEach(([s, a]) => {
|
|
240
|
+
e += ` --line-height-${s}: ${a}px;
|
|
241
241
|
`;
|
|
242
|
-
}), o.weights && Object.entries(o.weights).forEach(([s,
|
|
243
|
-
e += ` --font-weight-${s}: ${
|
|
242
|
+
}), o.weights && Object.entries(o.weights).forEach(([s, a]) => {
|
|
243
|
+
e += ` --font-weight-${s}: ${a};
|
|
244
244
|
`;
|
|
245
245
|
});
|
|
246
|
-
const
|
|
247
|
-
e += ` --space-unit: ${
|
|
248
|
-
`, Object.entries(n.spacing).forEach(([s,
|
|
249
|
-
s !== "unit" && (e += ` --space-${s}: ${
|
|
246
|
+
const c = n.spacing.unit || 4;
|
|
247
|
+
e += ` --space-unit: ${c}px;
|
|
248
|
+
`, Object.entries(n.spacing).forEach(([s, a]) => {
|
|
249
|
+
s !== "unit" && (e += ` --space-${s}: ${a}px;
|
|
250
250
|
`);
|
|
251
|
-
}), Object.entries(n.radius).forEach(([s,
|
|
252
|
-
e += ` --radius-${s}: ${
|
|
251
|
+
}), Object.entries(n.radius).forEach(([s, a]) => {
|
|
252
|
+
e += ` --radius-${s}: ${a}px;
|
|
253
253
|
`;
|
|
254
|
-
}), n.shadows && Object.entries(n.shadows).forEach(([s,
|
|
255
|
-
e += ` --shadow-${s}: ${
|
|
254
|
+
}), n.shadows && Object.entries(n.shadows).forEach(([s, a]) => {
|
|
255
|
+
e += ` --shadow-${s}: ${a};
|
|
256
256
|
`;
|
|
257
257
|
}), e += `}
|
|
258
258
|
`, e += `html { font-size: var(--font-size-base); }
|
|
259
259
|
`, e += `body { font-family: var(--font-family); }
|
|
260
260
|
`, t.textContent = e;
|
|
261
|
-
const
|
|
262
|
-
|
|
261
|
+
const i = document.getElementById("ds-theme");
|
|
262
|
+
i && i.remove(), document.head.appendChild(t);
|
|
263
263
|
}
|
|
264
264
|
const C = S(null);
|
|
265
|
-
function
|
|
266
|
-
const t =
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
function j({ tokens: r = {}, children: n }) {
|
|
266
|
+
const t = g(() => h(r), [r]);
|
|
267
|
+
B(() => {
|
|
268
|
+
E(t);
|
|
269
269
|
}, [t]);
|
|
270
|
-
const e =
|
|
270
|
+
const e = g(() => ({
|
|
271
271
|
tokens: t,
|
|
272
272
|
getToken: (o) => {
|
|
273
|
-
const
|
|
274
|
-
let
|
|
275
|
-
for (const s of
|
|
276
|
-
if (
|
|
277
|
-
|
|
273
|
+
const c = o.split(".");
|
|
274
|
+
let i = t;
|
|
275
|
+
for (const s of c)
|
|
276
|
+
if (i && typeof i == "object" && s in i)
|
|
277
|
+
i = i[s];
|
|
278
278
|
else
|
|
279
279
|
return;
|
|
280
|
-
return
|
|
280
|
+
return i;
|
|
281
281
|
}
|
|
282
282
|
}), [t]);
|
|
283
|
-
return /* @__PURE__ */
|
|
283
|
+
return /* @__PURE__ */ y(C.Provider, { value: e, children: n });
|
|
284
284
|
}
|
|
285
|
-
|
|
286
|
-
tokens:
|
|
287
|
-
children:
|
|
285
|
+
j.propTypes = {
|
|
286
|
+
tokens: l.object,
|
|
287
|
+
children: l.node.isRequired
|
|
288
288
|
};
|
|
289
|
-
function
|
|
289
|
+
function T() {
|
|
290
290
|
const r = D(C);
|
|
291
291
|
return r || (console.warn("useTheme must be used within ThemeProvider. Using default tokens."), {
|
|
292
|
-
tokens:
|
|
292
|
+
tokens: d,
|
|
293
293
|
getToken: (n) => {
|
|
294
294
|
const t = n.split(".");
|
|
295
|
-
let e =
|
|
295
|
+
let e = d;
|
|
296
296
|
for (const o of t)
|
|
297
297
|
if (e && typeof e == "object" && o in e)
|
|
298
298
|
e = e[o];
|
|
@@ -302,8 +302,8 @@ function k() {
|
|
|
302
302
|
}
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
|
-
function
|
|
306
|
-
const { tokens: r, getToken: n } =
|
|
305
|
+
function v() {
|
|
306
|
+
const { tokens: r, getToken: n } = T();
|
|
307
307
|
return {
|
|
308
308
|
/**
|
|
309
309
|
* دریافت رنگ
|
|
@@ -313,8 +313,8 @@ function w() {
|
|
|
313
313
|
color: (t) => {
|
|
314
314
|
const e = n(`colors.${t}`);
|
|
315
315
|
if (e) return e;
|
|
316
|
-
const [o,
|
|
317
|
-
return `var(--${o}-${
|
|
316
|
+
const [o, c] = t.split(".");
|
|
317
|
+
return `var(--${o}-${c}, #000)`;
|
|
318
318
|
},
|
|
319
319
|
/**
|
|
320
320
|
* دریافت spacing
|
|
@@ -362,117 +362,183 @@ function w() {
|
|
|
362
362
|
getToken: n
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
function q() {
|
|
366
|
+
try {
|
|
367
|
+
const { transitions: r } = require("@mui/material/styles");
|
|
368
|
+
return r;
|
|
369
|
+
} catch {
|
|
370
|
+
throw new Error(
|
|
371
|
+
"@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید."
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function P() {
|
|
376
|
+
try {
|
|
377
|
+
const { useTheme: r } = require("@mui/material/styles");
|
|
378
|
+
return r;
|
|
379
|
+
} catch {
|
|
380
|
+
throw new Error(
|
|
381
|
+
"@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید."
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function U() {
|
|
386
|
+
try {
|
|
387
|
+
return require("@emotion/styled");
|
|
388
|
+
} catch {
|
|
389
|
+
throw new Error(
|
|
390
|
+
"@emotion/styled باید در پروژه نصب شود. لطفاً npm install @emotion/styled را اجرا کنید."
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function H() {
|
|
395
|
+
try {
|
|
396
|
+
const { Box: r } = require("@mui/material");
|
|
397
|
+
return r;
|
|
398
|
+
} catch {
|
|
399
|
+
throw new Error(
|
|
400
|
+
"@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید."
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function O() {
|
|
405
|
+
try {
|
|
406
|
+
const { ButtonBase: r } = require("@mui/material");
|
|
407
|
+
return r;
|
|
408
|
+
} catch {
|
|
409
|
+
throw new Error(
|
|
410
|
+
"@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید."
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const R = ({ variant: r = "primary", size: n = "md", children: t, className: e = "", sx: o, ...c }) => {
|
|
415
|
+
const { color: i, spacing: s, radius: a, typography: f } = v(), p = O(), $ = {
|
|
367
416
|
primary: {
|
|
368
|
-
backgroundColor:
|
|
417
|
+
backgroundColor: i("primary.500"),
|
|
369
418
|
color: "#ffffff",
|
|
370
|
-
border: "none"
|
|
419
|
+
border: "none",
|
|
420
|
+
"&:hover": {
|
|
421
|
+
backgroundColor: i("primary.600")
|
|
422
|
+
}
|
|
371
423
|
},
|
|
372
424
|
outline: {
|
|
373
425
|
backgroundColor: "transparent",
|
|
374
|
-
border: `2px solid ${
|
|
375
|
-
color:
|
|
426
|
+
border: `2px solid ${i("primary.500")}`,
|
|
427
|
+
color: i("primary.500"),
|
|
428
|
+
"&:hover": {
|
|
429
|
+
backgroundColor: i("primary.50")
|
|
430
|
+
}
|
|
376
431
|
},
|
|
377
432
|
text: {
|
|
378
433
|
backgroundColor: "transparent",
|
|
379
434
|
border: "none",
|
|
380
|
-
color:
|
|
435
|
+
color: i("primary.500"),
|
|
436
|
+
"&:hover": {
|
|
437
|
+
backgroundColor: i("primary.50")
|
|
438
|
+
}
|
|
381
439
|
},
|
|
382
440
|
secondary: {
|
|
383
|
-
backgroundColor:
|
|
384
|
-
color:
|
|
385
|
-
border: "none"
|
|
441
|
+
backgroundColor: i("neutral.200"),
|
|
442
|
+
color: i("neutral.900"),
|
|
443
|
+
border: "none",
|
|
444
|
+
"&:hover": {
|
|
445
|
+
backgroundColor: i("neutral.300")
|
|
446
|
+
}
|
|
386
447
|
},
|
|
387
448
|
success: {
|
|
388
|
-
backgroundColor:
|
|
449
|
+
backgroundColor: i("success.500"),
|
|
389
450
|
color: "#ffffff",
|
|
390
|
-
border: "none"
|
|
451
|
+
border: "none",
|
|
452
|
+
"&:hover": {
|
|
453
|
+
backgroundColor: i("success.600")
|
|
454
|
+
}
|
|
391
455
|
},
|
|
392
456
|
error: {
|
|
393
|
-
backgroundColor:
|
|
457
|
+
backgroundColor: i("error.500"),
|
|
394
458
|
color: "#ffffff",
|
|
395
|
-
border: "none"
|
|
459
|
+
border: "none",
|
|
460
|
+
"&:hover": {
|
|
461
|
+
backgroundColor: i("error.600")
|
|
462
|
+
}
|
|
396
463
|
}
|
|
397
|
-
},
|
|
464
|
+
}, x = {
|
|
398
465
|
sm: {
|
|
399
|
-
padding: `${
|
|
400
|
-
fontSize:
|
|
466
|
+
padding: `${s(2)} ${s(4)}`,
|
|
467
|
+
fontSize: f("sizes.14") || "14px"
|
|
401
468
|
},
|
|
402
469
|
md: {
|
|
403
|
-
padding: `${
|
|
404
|
-
fontSize:
|
|
470
|
+
padding: `${s(3)} ${s(6)}`,
|
|
471
|
+
fontSize: f("sizes.16") || "16px"
|
|
405
472
|
},
|
|
406
473
|
lg: {
|
|
407
|
-
padding: `${
|
|
408
|
-
fontSize:
|
|
474
|
+
padding: `${s(4)} ${s(8)}`,
|
|
475
|
+
fontSize: f("sizes.18") || "18px"
|
|
409
476
|
}
|
|
410
477
|
};
|
|
411
|
-
return /* @__PURE__ */
|
|
412
|
-
|
|
478
|
+
return /* @__PURE__ */ y(
|
|
479
|
+
p,
|
|
413
480
|
{
|
|
414
481
|
className: `ds-button ds-button--${r} ds-button--${n} ${e}`,
|
|
415
|
-
|
|
416
|
-
borderRadius:
|
|
417
|
-
fontFamily:
|
|
482
|
+
sx: {
|
|
483
|
+
borderRadius: a("md"),
|
|
484
|
+
fontFamily: f("fontFamily"),
|
|
418
485
|
fontWeight: "500",
|
|
419
486
|
cursor: "pointer",
|
|
420
|
-
|
|
421
|
-
...
|
|
422
|
-
...
|
|
423
|
-
...o.style
|
|
424
|
-
},
|
|
425
|
-
onMouseEnter: (u) => {
|
|
426
|
-
r === "primary" && (u.currentTarget.style.opacity = "0.9");
|
|
427
|
-
},
|
|
428
|
-
onMouseLeave: (u) => {
|
|
429
|
-
r === "primary" && (u.currentTarget.style.opacity = "1");
|
|
487
|
+
...$[r],
|
|
488
|
+
...x[n],
|
|
489
|
+
...o
|
|
430
490
|
},
|
|
431
|
-
...
|
|
491
|
+
...c,
|
|
432
492
|
children: t
|
|
433
493
|
}
|
|
434
494
|
);
|
|
435
495
|
};
|
|
436
|
-
|
|
437
|
-
children:
|
|
438
|
-
variant:
|
|
439
|
-
size:
|
|
440
|
-
className:
|
|
496
|
+
R.propTypes = {
|
|
497
|
+
children: l.node.isRequired,
|
|
498
|
+
variant: l.oneOf(["primary", "outline", "text", "secondary", "success", "error"]),
|
|
499
|
+
size: l.oneOf(["sm", "md", "lg"]),
|
|
500
|
+
className: l.string,
|
|
501
|
+
sx: l.object
|
|
441
502
|
};
|
|
442
|
-
function
|
|
443
|
-
|
|
503
|
+
function L(r = {}) {
|
|
504
|
+
E(r);
|
|
444
505
|
}
|
|
445
|
-
const
|
|
446
|
-
function
|
|
506
|
+
const I = {};
|
|
507
|
+
function Y(r = {}) {
|
|
447
508
|
let n = "";
|
|
448
509
|
Object.entries(r.colors?.primary || {}).forEach(([t, e]) => {
|
|
449
510
|
n += `$primary-${t}: ${e};
|
|
450
511
|
`;
|
|
451
512
|
}), n += `$font-family: "${r.typography?.fontFamily || "sans-serif"}";
|
|
452
513
|
`, n += `$font-size-base: ${r.typography?.baseSize || 16}px;
|
|
453
|
-
`,
|
|
514
|
+
`, I.writeFileSync("custom-variables.scss", n);
|
|
454
515
|
}
|
|
455
|
-
const
|
|
516
|
+
const K = {
|
|
456
517
|
colors: {
|
|
457
|
-
primary:
|
|
458
|
-
neutral:
|
|
518
|
+
primary: b.primary,
|
|
519
|
+
neutral: b.neutral
|
|
459
520
|
},
|
|
460
521
|
spacing: { unit: 4 },
|
|
461
522
|
// 1 = 4px
|
|
462
523
|
typography: { fontFamily: "system-ui, sans-serif", baseSize: 16 }
|
|
463
524
|
};
|
|
464
525
|
export {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
526
|
+
R as Button,
|
|
527
|
+
j as ThemeProvider,
|
|
528
|
+
d as baseTokens,
|
|
468
529
|
h as createTokens,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
530
|
+
j as default,
|
|
531
|
+
b as defaultColors,
|
|
532
|
+
K as defaultConfig,
|
|
533
|
+
w as defaultTokens,
|
|
534
|
+
Y as generateSCSS,
|
|
535
|
+
E as generateTheme,
|
|
536
|
+
H as getMUIBox,
|
|
537
|
+
O as getMUIButtonBase,
|
|
538
|
+
U as getMUIStyled,
|
|
539
|
+
P as getMUITheme,
|
|
540
|
+
q as getMUITransitions,
|
|
541
|
+
L as injectCSS,
|
|
542
|
+
T as useTheme,
|
|
543
|
+
v as useTokens
|
|
478
544
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ali-mohammadi-design-system",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "خنثی و dynamic Design System — tokens از پروژه میاد",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"prop-types": "^15.8.1",
|
|
30
30
|
"react": ">=18 <20",
|
|
31
|
-
"react-dom": ">=18 <20"
|
|
31
|
+
"react-dom": ">=18 <20",
|
|
32
|
+
"@mui/material": "^5.0.0 || ^6.0.0",
|
|
33
|
+
"@emotion/react": "^11.0.0",
|
|
34
|
+
"@emotion/styled": "^11.0.0"
|
|
32
35
|
},
|
|
33
36
|
"exports": {
|
|
34
37
|
".": {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useTokens } from '../../utils/useTokens.js';
|
|
4
|
+
import { getMUIButtonBase } from '../../utils/muiHelpers.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
* Button Component - کامپوننت دکمه
|
|
7
|
+
* Button Component - کامپوننت دکمه بر اساس MUI ButtonBase
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```jsx
|
|
@@ -13,39 +14,58 @@ import { useTokens } from '../../utils/useTokens.js';
|
|
|
13
14
|
* <Button variant="outline" size="lg">Outline Button</Button>
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
const Button = ({ variant = 'primary', size = 'md', children, className = '', ...props }) => {
|
|
17
|
+
const Button = ({ variant = 'primary', size = 'md', children, className = '', sx, ...props }) => {
|
|
17
18
|
const { color, spacing, radius, typography } = useTokens();
|
|
19
|
+
const ButtonBase = getMUIButtonBase();
|
|
18
20
|
|
|
19
21
|
const variantStyles = {
|
|
20
22
|
primary: {
|
|
21
23
|
backgroundColor: color('primary.500'),
|
|
22
24
|
color: '#ffffff',
|
|
23
25
|
border: 'none',
|
|
26
|
+
'&:hover': {
|
|
27
|
+
backgroundColor: color('primary.600'),
|
|
28
|
+
},
|
|
24
29
|
},
|
|
25
30
|
outline: {
|
|
26
31
|
backgroundColor: 'transparent',
|
|
27
32
|
border: `2px solid ${color('primary.500')}`,
|
|
28
33
|
color: color('primary.500'),
|
|
34
|
+
'&:hover': {
|
|
35
|
+
backgroundColor: color('primary.50'),
|
|
36
|
+
},
|
|
29
37
|
},
|
|
30
38
|
text: {
|
|
31
39
|
backgroundColor: 'transparent',
|
|
32
40
|
border: 'none',
|
|
33
41
|
color: color('primary.500'),
|
|
42
|
+
'&:hover': {
|
|
43
|
+
backgroundColor: color('primary.50'),
|
|
44
|
+
},
|
|
34
45
|
},
|
|
35
46
|
secondary: {
|
|
36
47
|
backgroundColor: color('neutral.200'),
|
|
37
48
|
color: color('neutral.900'),
|
|
38
49
|
border: 'none',
|
|
50
|
+
'&:hover': {
|
|
51
|
+
backgroundColor: color('neutral.300'),
|
|
52
|
+
},
|
|
39
53
|
},
|
|
40
54
|
success: {
|
|
41
55
|
backgroundColor: color('success.500'),
|
|
42
56
|
color: '#ffffff',
|
|
43
57
|
border: 'none',
|
|
58
|
+
'&:hover': {
|
|
59
|
+
backgroundColor: color('success.600'),
|
|
60
|
+
},
|
|
44
61
|
},
|
|
45
62
|
error: {
|
|
46
63
|
backgroundColor: color('error.500'),
|
|
47
64
|
color: '#ffffff',
|
|
48
65
|
border: 'none',
|
|
66
|
+
'&:hover': {
|
|
67
|
+
backgroundColor: color('error.600'),
|
|
68
|
+
},
|
|
49
69
|
},
|
|
50
70
|
};
|
|
51
71
|
|
|
@@ -65,32 +85,21 @@ const Button = ({ variant = 'primary', size = 'md', children, className = '', ..
|
|
|
65
85
|
};
|
|
66
86
|
|
|
67
87
|
return (
|
|
68
|
-
<
|
|
88
|
+
<ButtonBase
|
|
69
89
|
className={`ds-button ds-button--${variant} ds-button--${size} ${className}`}
|
|
70
|
-
|
|
90
|
+
sx={{
|
|
71
91
|
borderRadius: radius('md'),
|
|
72
92
|
fontFamily: typography('fontFamily'),
|
|
73
93
|
fontWeight: '500',
|
|
74
94
|
cursor: 'pointer',
|
|
75
|
-
transition: 'all 0.2s ease',
|
|
76
95
|
...variantStyles[variant],
|
|
77
96
|
...sizeStyles[size],
|
|
78
|
-
...
|
|
79
|
-
}}
|
|
80
|
-
onMouseEnter={(e) => {
|
|
81
|
-
if (variant === 'primary') {
|
|
82
|
-
e.currentTarget.style.opacity = '0.9';
|
|
83
|
-
}
|
|
84
|
-
}}
|
|
85
|
-
onMouseLeave={(e) => {
|
|
86
|
-
if (variant === 'primary') {
|
|
87
|
-
e.currentTarget.style.opacity = '1';
|
|
88
|
-
}
|
|
97
|
+
...sx,
|
|
89
98
|
}}
|
|
90
99
|
{...props}
|
|
91
100
|
>
|
|
92
101
|
{children}
|
|
93
|
-
</
|
|
102
|
+
</ButtonBase>
|
|
94
103
|
);
|
|
95
104
|
};
|
|
96
105
|
|
|
@@ -99,6 +108,7 @@ Button.propTypes = {
|
|
|
99
108
|
variant: PropTypes.oneOf(['primary', 'outline', 'text', 'secondary', 'success', 'error']),
|
|
100
109
|
size: PropTypes.oneOf(['sm', 'md', 'lg']),
|
|
101
110
|
className: PropTypes.string,
|
|
111
|
+
sx: PropTypes.object,
|
|
102
112
|
};
|
|
103
113
|
|
|
104
|
-
export default Button;
|
|
114
|
+
export default Button;
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,9 @@ export * from './components/index.js';
|
|
|
5
5
|
export { ThemeProvider, useTheme } from './theme/ThemeProvider.jsx';
|
|
6
6
|
export { useTokens } from './utils/useTokens.js';
|
|
7
7
|
|
|
8
|
+
// Export MUI Helpers
|
|
9
|
+
export { getMUITransitions, getMUITheme, getMUIStyled, getMUIBox, getMUIButtonBase } from './utils/muiHelpers.js';
|
|
10
|
+
|
|
8
11
|
// Export توکنها
|
|
9
12
|
export { defaultTokens, baseTokens, createTokens, defaultColors } from './tokens/index.js';
|
|
10
13
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions برای استفاده از MUI
|
|
3
|
+
* این فایل wrapper برای MUI transitions و utilities است
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* دریافت MUI transitions
|
|
8
|
+
* @returns {Object} MUI transitions object
|
|
9
|
+
*/
|
|
10
|
+
export function getMUITransitions() {
|
|
11
|
+
try {
|
|
12
|
+
const { transitions } = require('@mui/material/styles');
|
|
13
|
+
return transitions;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
'@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید.'
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* دریافت MUI theme
|
|
23
|
+
* @returns {Object} MUI theme object
|
|
24
|
+
*/
|
|
25
|
+
export function getMUITheme() {
|
|
26
|
+
try {
|
|
27
|
+
const { useTheme } = require('@mui/material/styles');
|
|
28
|
+
return useTheme;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material @emotion/react @emotion/styled را اجرا کنید.'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* دریافت MUI styled
|
|
38
|
+
* @returns {Function} MUI styled function
|
|
39
|
+
*/
|
|
40
|
+
export function getMUIStyled() {
|
|
41
|
+
try {
|
|
42
|
+
const styled = require('@emotion/styled');
|
|
43
|
+
return styled;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'@emotion/styled باید در پروژه نصب شود. لطفاً npm install @emotion/styled را اجرا کنید.'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* دریافت MUI Box
|
|
53
|
+
* @returns {Component} MUI Box component
|
|
54
|
+
*/
|
|
55
|
+
export function getMUIBox() {
|
|
56
|
+
try {
|
|
57
|
+
const { Box } = require('@mui/material');
|
|
58
|
+
return Box;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید.'
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* دریافت MUI ButtonBase
|
|
68
|
+
* @returns {Component} MUI ButtonBase component
|
|
69
|
+
*/
|
|
70
|
+
export function getMUIButtonBase() {
|
|
71
|
+
try {
|
|
72
|
+
const { ButtonBase } = require('@mui/material');
|
|
73
|
+
return ButtonBase;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
'@mui/material باید در پروژه نصب شود. لطفاً npm install @mui/material را اجرا کنید.'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default {
|
|
82
|
+
getMUITransitions,
|
|
83
|
+
getMUITheme,
|
|
84
|
+
getMUIStyled,
|
|
85
|
+
getMUIBox,
|
|
86
|
+
getMUIButtonBase,
|
|
87
|
+
};
|
|
88
|
+
|