@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.
Files changed (3) hide show
  1. package/index.d.ts +30 -7
  2. package/index.js +95 -32
  3. package/package.json +8 -4
package/index.d.ts CHANGED
@@ -1,10 +1,33 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ButtonHTMLAttributes } from 'react';
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
- interface PropsButton extends ButtonHTMLAttributes<HTMLButtonElement> {
5
- text?: string;
6
- isLoading?: boolean;
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 function Button({ isLoading, text, children, ...rest }: PropsButton): react_jsx_runtime.JSX.Element;
31
+ declare const Button: React.NamedExoticComponent<ButtonProps>;
9
32
 
10
- export { type PropsButton, Button as default };
33
+ export { Button, type ButtonProps };
package/index.js CHANGED
@@ -1,38 +1,101 @@
1
- "use strict";var P=Object.create;var i=Object.defineProperty,S=Object.defineProperties,H=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertyNames,a=Object.getOwnPropertySymbols,A=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var B=(o,t,n)=>t in o?i(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,y=(o,t)=>{for(var n in t||(t={}))l.call(t,n)&&B(o,n,t[n]);if(a)for(var n of a(t))C.call(t,n)&&B(o,n,t[n]);return o},$=(o,t)=>S(o,M(t));var x=(o,t)=>{var n={};for(var r in o)l.call(o,r)&&t.indexOf(r)<0&&(n[r]=o[r]);if(o!=null&&a)for(var r of a(o))t.indexOf(r)<0&&C.call(o,r)&&(n[r]=o[r]);return n};var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},L=(o,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of v(t))!l.call(o,e)&&e!==n&&i(o,e,{get:()=>t[e],enumerable:!(r=H(t,e))||r.enumerable});return o};var u=(o,t,n)=>(n=o!=null?P(A(o)):{},L(t||!o||!o.__esModule?i(n,"default",{value:o,enumerable:!0}):n,o)),R=o=>L(i({},"__esModule",{value:!0}),o);var q={};N(q,{default:()=>k});module.exports=R(q);var s=u(require("styled-components"));var w=require("@mui/material"),d=u(require("styled-components")),m=u(require("@mobilestockweb/tools")),c=require("react/jsx-runtime");function T({isLoading:o,text:t,children:n,$color:r}){switch(!0){case o:return(0,c.jsx)(z,{className:"circular",$color:r});case!!t:return(0,c.jsx)(E,{$color:r,children:t});default:return n}}var z=(0,d.default)(w.CircularProgress)`
2
- width: 1rem !important;
3
- height: 1rem !important;
4
- svg {
5
- margin-right: 0;
6
- color: ${({$color:o})=>m.default.defineTextColor(o)};
7
- }
8
- `,E=d.default.span`
9
- text-transform: uppercase;
10
- color: ${({$color:o})=>m.default.defineTextColor(o)};
11
- `;var p=require("react/jsx-runtime");function k(e){var f=e,{isLoading:o,text:t,children:n}=f,r=x(f,["isLoading","text","children"]);var b,h;let g=(0,s.useTheme)();return(0,p.jsx)(O,$(y({},r),{$backgroundColor:((b=r==null?void 0:r.style)==null?void 0:b.backgroundColor)||g.colors.button.default,children:(0,p.jsx)(T,{isLoading:o,text:t,$color:((h=r==null?void 0:r.style)==null?void 0:h.backgroundColor)||g.colors.button.default,children:n})}))}var O=s.default.button`
12
- display: flex;
13
- align-items: center;
14
- justify-content: center;
15
-
16
- width: 100%;
17
- min-height: 3rem;
18
- padding: 0.9rem 1rem;
19
-
20
- font-size: 0.9rem;
21
- font-family: 'Open Sans', sans-serif;
22
- font-weight: 400;
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
- cursor: pointer;
76
+ &:not(:disabled):hover {
77
+ ${({$variant:t,$backgroundColor:e,theme:o})=>H(t,e,o)}
78
+ }
27
79
 
28
- box-shadow: 0 0.25rem 0.25rem ${({theme:o})=>o.colors.button.shadow};
29
- border: none;
30
- border-radius: 0.4rem;
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
- &:disabled {
36
- opacity: 0.7;
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.11",
3
+ "version": "1.0.0",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
- "@mobilestockweb/tools": "^0.0.13"
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
  }