@mobilestockweb/button 0.0.11 → 1.0.0
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/index.d.ts +30 -7
- package/index.js +95 -32
- package/package.json +8 -4
package/index.d.ts
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { DefaultTheme } from 'styled-components';
|
|
2
|
+
import React, { ReactElement } from 'react';
|
|
3
|
+
import { ClickableProps } from '@mobilestockweb/clickable';
|
|
4
|
+
import { ViewBaseProps } from '@mobilestockweb/container';
|
|
5
|
+
import { IconName } from '@mobilestockweb/icons';
|
|
6
|
+
import { TypographyProps } from '@mobilestockweb/typography';
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
type Sizes = Uppercase<keyof DefaultTheme['font']['size'] & string>;
|
|
9
|
+
type ButtonColor = Uppercase<keyof DefaultTheme['colors']['button'] & string>;
|
|
10
|
+
type Shade = 'LIGHT' | 'DARK';
|
|
11
|
+
type BackgroundColor = `${ButtonColor}_${Shade}` | ButtonColor;
|
|
12
|
+
type Variant = 'DEFAULT' | 'LINK' | 'TRANSPARENT' | 'OUTLINE';
|
|
13
|
+
type IconAlign = 'START' | 'BEFORE-TEXT' | 'AFTER-TEXT' | 'ABOVE-TEXT' | 'END';
|
|
14
|
+
type TextAlign = 'START' | 'CENTER' | 'END';
|
|
15
|
+
type NotificationPosition = 'ICON' | 'TEXT' | 'END';
|
|
16
|
+
interface ButtonProps extends Omit<ClickableProps, 'children' | 'size'> {
|
|
17
|
+
text?: string | ReactElement;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
circular?: boolean;
|
|
20
|
+
notification?: number;
|
|
21
|
+
size?: Sizes;
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
fontWeight?: TypographyProps['weight'];
|
|
24
|
+
variant?: Variant;
|
|
25
|
+
iconAlign?: IconAlign;
|
|
26
|
+
textAlign?: TextAlign;
|
|
27
|
+
notificationPosition?: NotificationPosition;
|
|
28
|
+
backgroundColor?: BackgroundColor;
|
|
29
|
+
padding?: ViewBaseProps['padding'];
|
|
7
30
|
}
|
|
8
|
-
declare
|
|
31
|
+
declare const Button: React.NamedExoticComponent<ButtonProps>;
|
|
9
32
|
|
|
10
|
-
export {
|
|
33
|
+
export { Button, type ButtonProps };
|
package/index.js
CHANGED
|
@@ -1,38 +1,101 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
"use strict";var at=Object.create;var x=Object.defineProperty,st=Object.defineProperties,ct=Object.getOwnPropertyDescriptor,lt=Object.getOwnPropertyDescriptors,dt=Object.getOwnPropertyNames,y=Object.getOwnPropertySymbols,ut=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var F=(t,e,o)=>e in t?x(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,U=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&F(t,o,e[o]);if(y)for(var o of y(e))X.call(e,o)&&F(t,o,e[o]);return t},O=(t,e)=>st(t,lt(e));var V=(t,e)=>{var o={};for(var i in t)$.call(t,i)&&e.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&y)for(var i of y(t))e.indexOf(i)<0&&X.call(t,i)&&(o[i]=t[i]);return o};var ft=(t,e)=>{for(var o in e)x(t,o,{get:e[o],enumerable:!0})},W=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of dt(e))!$.call(t,s)&&s!==o&&x(t,s,{get:()=>e[s],enumerable:!(i=ct(e,s))||i.enumerable});return t};var p=(t,e,o)=>(o=t!=null?at(ut(t)):{},W(e||!t||!t.__esModule?x(o,"default",{value:t,enumerable:!0}):o,t)),pt=t=>W(x({},"__esModule",{value:!0}),t);var Rt={};ft(Rt,{Button:()=>tt});module.exports=pt(Rt);var b=p(require("react")),d=p(require("styled-components")),Y=require("@mobilestockweb/clickable"),N=require("@mobilestockweb/container"),q=p(require("@mobilestockweb/tools")),Q=require("@mobilestockweb/typography");var h=p(require("chroma-js")),n=require("styled-components"),A=p(require("@mobilestockweb/tools"));function C(t,e){let o=t.split("_"),i=500;if(o.length>1)switch(o[1]){case"LIGHT":i=400;break;case"DARK":i=600;break}return A.default.getColorWithLuminosity(e.colors.button[o[0].toLowerCase()],i)}function M(t,e,o){let i=C(e,o);switch(t){case"DEFAULT":return n.css`
|
|
2
|
+
background-color: ${(0,h.default)(i).shade(.5).css()};
|
|
3
|
+
`;case"OUTLINE":return n.css`
|
|
4
|
+
border: 2px solid ${(0,h.default)(i).shade(.5).css()};
|
|
5
|
+
`;default:return""}}function H(t,e,o){let i=C(e,o);switch(t){case"DEFAULT":return n.css`
|
|
6
|
+
background-color: ${(0,h.default)(i).shade(.25).css()};
|
|
7
|
+
`;case"OUTLINE":return n.css`
|
|
8
|
+
border: 2px solid ${(0,h.default)(i).shade(.25).css()};
|
|
9
|
+
`;case"LINK":return n.css`
|
|
10
|
+
* {
|
|
11
|
+
color: ${i};
|
|
12
|
+
}
|
|
13
|
+
`;case"TRANSPARENT":return""}}function B(t){switch(t){case"START":return n.css`
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
`;case"BEFORE-TEXT":return n.css`
|
|
16
|
+
justify-content: center;
|
|
17
|
+
`;case"AFTER-TEXT":return n.css`
|
|
18
|
+
flex-direction: row-reverse;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
`;case"ABOVE-TEXT":return n.css`
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
`;case"END":return n.css`
|
|
23
|
+
flex-direction: row-reverse;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
`}}function K(t){switch(t){case"START":return n.css`
|
|
26
|
+
justify-content: flex-start;
|
|
27
|
+
`;case"CENTER":return n.css`
|
|
28
|
+
justify-content: center;
|
|
29
|
+
`;case"END":return n.css`
|
|
30
|
+
justify-content: flex-end;
|
|
31
|
+
`}}function _(t,e,o){let i=C(e,o);switch(t){case"DEFAULT":return n.css`
|
|
32
|
+
background-color: ${i};
|
|
33
|
+
* {
|
|
34
|
+
color: ${A.default.defineTextColor(i)};
|
|
35
|
+
}
|
|
36
|
+
`;case"OUTLINE":return n.css`
|
|
37
|
+
border: 2px solid ${i};
|
|
38
|
+
* {
|
|
39
|
+
color: ${i};
|
|
40
|
+
}
|
|
41
|
+
`;case"LINK":return n.css`
|
|
42
|
+
* {
|
|
43
|
+
color: ${o.colors.text.default};
|
|
44
|
+
}
|
|
45
|
+
`;case"TRANSPARENT":return n.css`
|
|
46
|
+
* {
|
|
47
|
+
color: ${i};
|
|
48
|
+
}
|
|
49
|
+
`}}function j(t,e,o){let i=3;e&&(i=4);let a={XS:{padding:"0.25rem 0.75rem",borderRadius:`${parseFloat(o.borderRadius.default)+1}px`},SM:{padding:"0.5rem 1rem",borderRadius:`${parseFloat(o.borderRadius.default)+1}px`},MD:{padding:"0.75rem 1.25rem",borderRadius:`${parseFloat(o.borderRadius.default)+3}px`},LG:{padding:"1rem 1.75rem",borderRadius:`${parseFloat(o.borderRadius.default)+3}px`},XL:{padding:"1.25rem 2.25rem",borderRadius:`${parseFloat(o.borderRadius.default)+5}px`},"2XL":{padding:"1.5rem 2.75rem",borderRadius:`${parseFloat(o.borderRadius.default)+7}px`},"3XL":{padding:"1.75rem 3.25rem",borderRadius:`${parseFloat(o.borderRadius.default)+9}px`}}[t],T=n.css`
|
|
50
|
+
padding: ${e?"0":a.padding};
|
|
51
|
+
border-radius: ${e?o.borderRadius.rounded:a.borderRadius};
|
|
52
|
+
`;if(e){let E=`${i*parseFloat(o.spacing[t.toLowerCase()])}rem`;return n.css`
|
|
53
|
+
${T}
|
|
54
|
+
width: ${E};
|
|
55
|
+
min-height: ${E};
|
|
56
|
+
`}return T}var S=require("@mobilestockweb/icons");var g=p(require("styled-components")),G=p(require("@mobilestockweb/tools")),J=require("@mobilestockweb/typography"),P=require("react/jsx-runtime");function m(t){return(0,P.jsx)(mt,{$position:t.notificationPosition,$size:t.size,children:(0,P.jsx)(Tt,{size:t.size,weight:"BOLD",children:t.notification>99?"99+":t.notification})})}var gt={XS:{top:"-10px",right:"-10px"},SM:{top:"-12px",right:"-11px"},MD:{top:"-13px",right:"-12px"},LG:{top:"-15px",right:"-10px"},XL:{top:"-20px",right:"-15px"},"2XL":{top:"-20px",right:"-15px"},"3XL":{top:"-25px",right:"-13px"}},mt=g.default.div`
|
|
57
|
+
position: absolute;
|
|
58
|
+
background-color: ${({theme:t})=>t.colors.alert.urgent};
|
|
59
|
+
padding: 0.125rem 0.25rem;
|
|
60
|
+
border-radius: 0.3rem;
|
|
23
61
|
|
|
62
|
+
${({$position:t,$size:e})=>{if(t==="END")return g.css`
|
|
63
|
+
position: static;
|
|
64
|
+
`;let o=gt[e];return g.css`
|
|
65
|
+
top: ${o.top};
|
|
66
|
+
right: ${o.right};
|
|
67
|
+
`}}
|
|
68
|
+
`,Tt=(0,g.default)(J.Typography)`
|
|
69
|
+
color: ${({theme:t})=>G.default.defineTextColor(t.colors.alert.urgent)} !important;
|
|
70
|
+
`;var c=require("react/jsx-runtime");function L(t){let e=t.notification&&t.notificationPosition==="ICON";return t.icon?e?(0,c.jsxs)(R,{children:[(0,c.jsx)(S.Icon,{name:t.icon,size:t.size}),(0,c.jsx)(m,{notification:t.notification,notificationPosition:t.notificationPosition,size:t.size})]}):(0,c.jsx)(S.Icon,{name:t.icon,size:t.size}):(0,c.jsx)(c.Fragment,{})}var I=require("@mobilestockweb/typography");var l=require("react/jsx-runtime");function D(t){return t.text?t.notification&&t.notificationPosition==="TEXT"?(0,l.jsxs)(R,{children:[(0,l.jsx)(I.Typography,{weight:t.fontWeight,size:t.size,withUnderline:t.withUnderline,children:t.text}),(0,l.jsx)(m,{notification:t.notification,notificationPosition:t.notificationPosition,size:t.size})]}):(0,l.jsx)(I.Typography,{weight:t.fontWeight,size:t.size,withUnderline:t.withUnderline,children:t.text}):(0,l.jsx)(l.Fragment,{})}var r=require("react/jsx-runtime"),Z=[{name:"div",component:"div"},{name:"Container",component:N.Container},{name:"Typography",component:Q.Typography}],xt=Z.map(t=>t.component),tt=b.default.memo(function(bt){var v=bt,{variant:e="DEFAULT",size:o="MD",iconAlign:i="BEFORE-TEXT",backgroundColor:s="DEFAULT",notificationPosition:a="ICON",fontWeight:T="REGULAR",textAlign:E="CENTER",circular:z=!1,notification:u,text:f,isLoading:k,icon:w,disabled:ot,padding:et}=v,it=V(v,["variant","size","iconAlign","backgroundColor","notificationPosition","fontWeight","textAlign","circular","notification","text","isLoading","icon","disabled","padding"]);let nt=(0,b.useRef)(null);if(typeof f!="string"&&f&&!q.default.validateJSXTree(f,xt))throw new Error(`Invalid jsx text props. Expected one of ${Z.map(rt=>rt.name).join(", ")}, but received: ${f.type.target||f.type}`);return(0,r.jsx)(ht,O(U({},it),{ref:nt,isLoading:k,disabled:ot||k,size:o,$backgroundColor:s,$variant:e,$circular:z,children:(0,r.jsxs)(Ct,{padding:et,gap:o,align:"CENTER",$textAlign:E,$iconAlign:i,children:[i!=="START"&&i!=="END"?(0,r.jsxs)(Et,{gap:i==="ABOVE-TEXT"?"NONE":o,align:"CENTER",$iconAlign:i,children:[(0,r.jsx)(L,{icon:w,size:o,notification:u,notificationPosition:a}),(0,r.jsx)(D,{text:f,fontWeight:T,size:o,withUnderline:e==="LINK",notification:u,notificationPosition:a})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(L,{icon:w,size:o,notification:u,notificationPosition:a}),(0,r.jsx)(D,{text:f,fontWeight:T,size:o,withUnderline:e==="LINK",notification:u,notificationPosition:a})]}),!!u&&a==="END"&&(0,r.jsx)(m,{notification:u,notificationPosition:a,size:o}),!u&&(i==="START"||i==="END")&&!z&&(0,r.jsx)(yt,{})]})}))}),ht=(0,d.default)(Y.Clickable)`
|
|
71
|
+
flex: 1;
|
|
24
72
|
user-select: none;
|
|
73
|
+
${({$variant:t,$backgroundColor:e,theme:o})=>_(t,e,o)}
|
|
74
|
+
${({size:t,$circular:e,theme:o})=>j(t,e,o)}
|
|
25
75
|
|
|
26
|
-
|
|
76
|
+
&:not(:disabled):hover {
|
|
77
|
+
${({$variant:t,$backgroundColor:e,theme:o})=>H(t,e,o)}
|
|
78
|
+
}
|
|
27
79
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
background-color: ${({$backgroundColor:o})=>o};
|
|
32
|
-
&:hover {
|
|
33
|
-
opacity: 0.8;
|
|
80
|
+
&:not(:disabled):active {
|
|
81
|
+
transform: scale(0.98);
|
|
82
|
+
${({$variant:t,$backgroundColor:e,theme:o})=>M(t,e,o)}
|
|
34
83
|
}
|
|
35
|
-
|
|
36
|
-
|
|
84
|
+
|
|
85
|
+
&:focus-visible {
|
|
86
|
+
outline-offset: 2px;
|
|
87
|
+
|
|
88
|
+
${({$backgroundColor:t,theme:e})=>{let o=C(t,e);return d.css`
|
|
89
|
+
outline: 3px solid ${o};
|
|
90
|
+
`}}
|
|
37
91
|
}
|
|
38
|
-
|
|
92
|
+
`,Ct=(0,d.default)(N.Container)`
|
|
93
|
+
${({$textAlign:t})=>K(t)};
|
|
94
|
+
${({$iconAlign:t})=>t==="START"||t==="END"?B(t):""};
|
|
95
|
+
`,R=d.default.div`
|
|
96
|
+
position: relative;
|
|
97
|
+
display: inline-flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
`,Et=(0,d.default)(N.Container)`
|
|
100
|
+
${({$iconAlign:t})=>B(t)};
|
|
101
|
+
`,yt=d.default.div``;0&&(module.exports={Button});
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilestockweb/button",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"
|
|
6
|
+
"chroma-js": "^3.1.2",
|
|
7
|
+
"@mobilestockweb/clickable": "^1.0.0",
|
|
8
|
+
"@mobilestockweb/container": "^0.0.2",
|
|
9
|
+
"@mobilestockweb/icons": "^0.0.4",
|
|
10
|
+
"@mobilestockweb/typography": "^0.0.4",
|
|
11
|
+
"@mobilestockweb/tools": "^0.0.14"
|
|
7
12
|
},
|
|
8
13
|
"peerDependencies": {
|
|
9
14
|
"react": "18.2.0",
|
|
10
15
|
"react-dom": "18.2.0",
|
|
11
|
-
"styled-components": "^6.1.8"
|
|
12
|
-
"@mui/material": "^6.1.10"
|
|
16
|
+
"styled-components": "^6.1.8"
|
|
13
17
|
}
|
|
14
18
|
}
|