@yahoo/uds 2.4.0 → 2.4.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/cli/bin/uds-darwin-arm64-baseline +0 -0
- package/cli/bin/uds-linux-arm64 +0 -0
- package/cli/bin/uds-linux-x64-baseline +0 -0
- package/cli/codemods/addCommentAboveComponents.ts +147 -0
- package/cli/commands/codemod/buttonType.ts +20 -0
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.js +2 -2
- package/dist/metafile-cjs.json +1 -1
- package/package.json +3 -3
Binary file
|
package/cli/bin/uds-linux-arm64
CHANGED
Binary file
|
Binary file
|
@@ -0,0 +1,147 @@
|
|
1
|
+
import path from 'node:path';
|
2
|
+
|
3
|
+
import { IndentationText, Node, Project, SourceFile, SyntaxKind } from 'ts-morph';
|
4
|
+
|
5
|
+
const getProject = () => {
|
6
|
+
const workspaceDir = Bun.env.PWD;
|
7
|
+
const srcDir = path.join(workspaceDir, 'tsconfig.json');
|
8
|
+
return new Project({
|
9
|
+
tsConfigFilePath: srcDir,
|
10
|
+
manipulationSettings: { indentationText: IndentationText.TwoSpaces },
|
11
|
+
});
|
12
|
+
};
|
13
|
+
|
14
|
+
const getGlobPattern = (selectedDirs?: string[]) => {
|
15
|
+
let glob = './';
|
16
|
+
if (selectedDirs && selectedDirs.length === 1) {
|
17
|
+
glob += selectedDirs[0];
|
18
|
+
} else if (selectedDirs) {
|
19
|
+
glob += `{${selectedDirs.join(',')}}`;
|
20
|
+
}
|
21
|
+
glob += '/**/*.+(ts|tsx)';
|
22
|
+
|
23
|
+
return glob;
|
24
|
+
};
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Gets the named imports being imported from `packageName` module.
|
28
|
+
* @param sourceFile Source file to search for imports in.
|
29
|
+
* @param packageName The package name to search in.
|
30
|
+
*/
|
31
|
+
const getImportsFromPackage = (sourceFile: SourceFile, packageName: string) => {
|
32
|
+
const importedComponents = new Set<string>();
|
33
|
+
|
34
|
+
// Collect imports from '@yahoo/uds'
|
35
|
+
sourceFile.getImportDeclarations().forEach((importDeclaration) => {
|
36
|
+
if (importDeclaration.getModuleSpecifierValue() === packageName) {
|
37
|
+
importDeclaration.getNamedImports().forEach((namedImport) => {
|
38
|
+
importedComponents.add(namedImport.getName());
|
39
|
+
});
|
40
|
+
}
|
41
|
+
});
|
42
|
+
|
43
|
+
return importedComponents;
|
44
|
+
};
|
45
|
+
|
46
|
+
/** Returns true if the jsx element has a `propertyName` prop. */
|
47
|
+
function hasJSXProperty(element: Node, propertyName: string) {
|
48
|
+
if (!Node.isJsxElement(element) && !Node.isJsxSelfClosingElement(element)) {
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
|
52
|
+
const openingElement = Node.isJsxElement(element) ? element.getOpeningElement() : element;
|
53
|
+
|
54
|
+
return openingElement
|
55
|
+
.getAttributes()
|
56
|
+
.some((attr) => Node.isJsxAttribute(attr) && attr.getNameNode().getText() === propertyName);
|
57
|
+
}
|
58
|
+
|
59
|
+
/** Returns true if the name of the jsx element is `tagName`. */
|
60
|
+
function matchesJSXTagName(element: Node, tagName: string) {
|
61
|
+
if (!Node.isJsxElement(element) && !Node.isJsxSelfClosingElement(element)) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
|
65
|
+
const tagNameNode = Node.isJsxElement(element)
|
66
|
+
? element.getOpeningElement().getTagNameNode()
|
67
|
+
: element.getTagNameNode();
|
68
|
+
|
69
|
+
return tagNameNode.getText() === tagName;
|
70
|
+
}
|
71
|
+
|
72
|
+
/** Gets the JSX elements in the source file. */
|
73
|
+
function getJSXElements(sourceFile: SourceFile) {
|
74
|
+
const jsxElements = [
|
75
|
+
...sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement),
|
76
|
+
...sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement),
|
77
|
+
];
|
78
|
+
return jsxElements;
|
79
|
+
}
|
80
|
+
|
81
|
+
interface LineInfo {
|
82
|
+
linePos: number;
|
83
|
+
lineNum: number;
|
84
|
+
indentAmount: number;
|
85
|
+
}
|
86
|
+
|
87
|
+
interface Options {
|
88
|
+
/** Comment to add above each component instance. */
|
89
|
+
comment: string;
|
90
|
+
/** Component names to target. */
|
91
|
+
componentNames: string[];
|
92
|
+
/** Package to look in. @default '@yahoo/uds' */
|
93
|
+
packageName?: string;
|
94
|
+
selectedDirs?: string[];
|
95
|
+
project?: Project;
|
96
|
+
}
|
97
|
+
|
98
|
+
export async function addCommentAboveComponents({
|
99
|
+
comment,
|
100
|
+
componentNames,
|
101
|
+
packageName = '@yahoo/uds',
|
102
|
+
selectedDirs,
|
103
|
+
project = getProject(),
|
104
|
+
}: Options) {
|
105
|
+
const glob = getGlobPattern(selectedDirs);
|
106
|
+
|
107
|
+
project.getSourceFiles(glob).forEach((sourceFile) => {
|
108
|
+
const importUdsComponents = getImportsFromPackage(sourceFile, packageName);
|
109
|
+
const jsxElements = getJSXElements(sourceFile);
|
110
|
+
const foundLines: LineInfo[] = [];
|
111
|
+
|
112
|
+
for (const element of jsxElements) {
|
113
|
+
for (const componentName of componentNames) {
|
114
|
+
// Component matches one(s) we're looking for?
|
115
|
+
const matchesName = matchesJSXTagName(element, componentName);
|
116
|
+
// Was imported from UDS package?
|
117
|
+
const wasImportedFromUDS = importUdsComponents.has(componentName);
|
118
|
+
// Has type prop.
|
119
|
+
const hasTypeProp = hasJSXProperty(element, 'type');
|
120
|
+
|
121
|
+
if (matchesName && wasImportedFromUDS && !hasTypeProp) {
|
122
|
+
foundLines.push({
|
123
|
+
linePos: element.getStartLinePos(true),
|
124
|
+
lineNum: element.getStartLineNumber(true),
|
125
|
+
indentAmount: element.getIndentationLevel(),
|
126
|
+
});
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
// For all the found components, add the comment above them.
|
132
|
+
if (foundLines.length) {
|
133
|
+
const srcLines = sourceFile.getText(true).split('\n');
|
134
|
+
foundLines.forEach(({ lineNum, indentAmount }, i) => {
|
135
|
+
const indent = Array(indentAmount).fill(IndentationText.TwoSpaces).join('');
|
136
|
+
// Insert above the line with the component.
|
137
|
+
srcLines.splice(lineNum + i - 1, 0, `${indent}${comment}`);
|
138
|
+
});
|
139
|
+
|
140
|
+
const updateSrc = srcLines.join('\n');
|
141
|
+
console.log(updateSrc);
|
142
|
+
sourceFile.replaceWithText(updateSrc);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
|
146
|
+
await project.save();
|
147
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { type Props, spinStart, spinStop } from 'bluebun';
|
2
|
+
|
3
|
+
import { addCommentAboveComponents } from '../../codemods/addCommentAboveComponents';
|
4
|
+
|
5
|
+
export default {
|
6
|
+
name: 'buttonType',
|
7
|
+
description: `Adds a comment if UDS buttons are missing type="submit" for form submission.`,
|
8
|
+
run: async (props: Props & { selectedDirs?: string[] }) => {
|
9
|
+
spinStart('Running codemod...');
|
10
|
+
|
11
|
+
await addCommentAboveComponents({
|
12
|
+
comment:
|
13
|
+
'{/* 🙏 TODO: verify this button does not need type="submit" for form submission. */}',
|
14
|
+
selectedDirs: props.selectedDirs,
|
15
|
+
componentNames: ['Button', 'IconButton'],
|
16
|
+
});
|
17
|
+
|
18
|
+
spinStop('Codemod complete! Peek the diff and commit your changes!');
|
19
|
+
},
|
20
|
+
};
|
package/dist/client/index.cjs
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
"use client";
|
2
|
-
"use strict";var t=require("../chunk-D5NBUCDY.cjs"),e=require("../chunk-TNA4SFJT.cjs"),o=require("../chunk-6URF5YHM.cjs"),n=require("../chunk-5WBROFT5.cjs"),r=require("@yahoo/uds/fixtures"),i=require("react/jsx-runtime"),a=require("motion/react"),s=require("react"),c={scale:.7,opacity:0},l={scale:[.7,.7,1],opacity:[0,0,1],transition:{times:[0,.5,1]}},d={icon:l,hide:c,loading:c},u={loading:l,hide:c,icon:c},
|
2
|
+
"use strict";var t=require("../chunk-D5NBUCDY.cjs"),e=require("../chunk-TNA4SFJT.cjs"),o=require("../chunk-6URF5YHM.cjs"),n=require("../chunk-5WBROFT5.cjs"),r=require("@yahoo/uds/fixtures"),i=require("react/jsx-runtime"),a=require("motion/react"),s=require("react"),c={scale:.7,opacity:0},l={scale:[.7,.7,1],opacity:[0,0,1],transition:{times:[0,.5,1]}},d={icon:l,hide:c,loading:c},u={loading:l,hide:c,icon:c},p=`var(${n.BUTTON_CSS_VAR_MAP.columnGap})`,m=`var(${n.BUTTON_CSS_VAR_MAP.iconSize})`,h={rest:{scale:`var(${n.BUTTON_CSS_VAR_MAP.effects.scale.rest})`},hover:{scale:`var(${n.BUTTON_CSS_VAR_MAP.effects.scale.hover})`},pressed:{scale:`var(${n.BUTTON_CSS_VAR_MAP.effects.scale.pressed})`},withoutIcon:{columnGap:"0px"},withIcon:{columnGap:p}},f={hide:{width:"0px",opacity:0,display:"none"},loading:{width:m,display:"flex",opacity:1},icon:{width:m,display:"flex",opacity:1}},g=({size:t,variant:e})=>{if("outline"===e)switch(t){case"sm":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M7.9 2.7a5.2 5.2 0 1 0 5.2 5.2h1.6a6.8 6.8 0 1 1-6.8-6.8.8.8 0 1 1 0 1.6"})});case"md":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M12 4a8 8 0 1 0 8 8h2c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2a1 1 0 1 1 0 2"})});case"lg":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M16.15 4.3C9.605 4.3 4.3 9.605 4.3 16.15S9.605 28 16.15 28 28 22.695 28 16.15h2.3c0 7.815-6.335 14.15-14.15 14.15S2 23.965 2 16.15 8.335 2 16.15 2a1.15 1.15 0 0 1 0 2.3"})})}if("fill"===e)switch(t){case"sm":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M8 2.9A5.1 5.1 0 1 0 13.1 8h1.8A6.9 6.9 0 1 1 8 1.1a.9.9 0 1 1 0 1.8"})});case"md":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M12.15 4.3A7.85 7.85 0 1 0 20 12.15h2.3c0 5.606-4.544 10.15-10.15 10.15S2 17.756 2 12.15 6.544 2 12.15 2a1.15 1.15 0 0 1 0 2.3"})});case"lg":return i.jsx(i.Fragment,{children:i.jsx("path",{fill:"currentColor",d:"M16.35 4.7C9.916 4.7 4.7 9.916 4.7 16.35S9.916 28 16.35 28 28 22.784 28 16.35h2.7c0 7.925-6.425 14.35-14.35 14.35S2 24.275 2 16.35 8.425 2 16.35 2a1.35 1.35 0 1 1 0 2.7"})})}return i.jsx(i.Fragment,{})},b=()=>import("../motionFeatures-HQUM526D.cjs").then((({domAnimation:t})=>t));/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */function x({reducedMotion:t="user",children:n,layoutVariant:r="subtle",layoutSpeed:c="3",colorVariant:l="smooth",colorSpeed:d="3"}){const u=o.motion[r][c],p=o.motion[l][d],[m,h]=s.useState(u),[f,g]=s.useState(p),x={variant:l,speed:d},S=e.getMotionVar({...x,control:"stiffness"}),v=e.getMotionVar({...x,control:"damping"}),j={variant:r,speed:c},C=e.getMotionVar({...j,control:"stiffness"}),y=e.getMotionVar({...j,control:"damping"});s.useEffect((()=>{const t=getComputedStyle(document.documentElement),e={damping:Number(t.getPropertyValue(y)),stiffness:Number(t.getPropertyValue(C))},o={damping:Number(t.getPropertyValue(v)),stiffness:Number(t.getPropertyValue(S))};h(e),g(o)}),[v,S,y,C]);const w=s.useMemo((()=>({type:"spring",mass:1,...m,layout:m,opacity:f,color:f,borderColor:f,backgroundColor:f})),[f,m]);return i.jsx(a.LazyMotion,{features:b,strict:!0,children:i.jsx(a.MotionConfig,{transition:w,reducedMotion:t,children:n})})}var S=t.createSlot(),v=a.m.create(S),j=s.forwardRef((function({palette:e,variant:o,size:n,startIcon:c,endIcon:l,iconVariant:p,loading:m,disableEffects:b,children:S,asChild:j,type:C="button",className:y,...w},M){const N=s.useRef(null);s.useImperativeHandle(M,(()=>N.current));const V=l?"icon":"hide",I=(({startIcon:t,endIcon:e,loading:o})=>t||e||o?"withIcon":"withoutIcon")({startIcon:c,endIcon:l,loading:m}),T=(({loading:t,startIcon:e})=>t?"loading":e?"icon":"hide")({loading:m,startIcon:c}),B={button:t.getStyles({buttonSize:n,buttonVariant:o,buttonPalette:e,className:t.cx("uds-button","uds-ring","uds-hit-target",m&&"uds-button-loading",b&&"uds-button-without-effects","withIcon"===I&&"uds-button-with-gap",y)}),content:"uds-button-content truncate",iconContainer:"uds-button-icon-container flex overflow-clip",loading:"uds-button-icon start-content animate-spin",start:"uds-button-icon start-content",end:"uds-button-icon end-content"},R=a.useReducedMotion()?"smooth":"subtle",z=s.useMemo((()=>i.jsx(a.m.span,{className:B.iconContainer,initial:!1,variants:f,animate:T,children:i.jsxs(a.AnimatePresence,{initial:!1,mode:"popLayout",children:[m&&i.jsx(a.m.span,{variants:u,initial:"hide",animate:"loading",exit:"hide",children:i.jsx(t.Icon,{size:r.buttonIconSvgSize,name:g,variant:p,color:"current",className:B.loading})},"loading"),c&&!m&&i.jsx(a.m.span,{variants:d,initial:"hide",animate:"icon",exit:"hide",children:i.jsx(t.Icon,{size:r.buttonIconSvgSize,name:c,variant:p,color:"current",className:B.start})},c.name)]})})),[B.iconContainer,B.loading,B.start,T,m,p,c]),A=s.useMemo((()=>i.jsx(a.m.span,{className:B.iconContainer,initial:!1,variants:f,animate:V,children:i.jsx(a.AnimatePresence,{initial:!1,mode:"popLayout",children:l&&i.jsx(a.m.span,{variants:d,initial:"hide",animate:"icon",exit:"hide",children:i.jsx(t.Icon,{size:r.buttonIconSvgSize,name:l,variant:p,color:"current",className:B.start})},l.name)})})),[B.iconContainer,B.start,l,V,p]),E=s.useMemo((()=>b?{...h,rest:{},hover:{},pressed:{}}:h),[b]);return j&&s.isValidElement(S)?i.jsx(x,{layoutSpeed:"3",layoutVariant:R,children:i.jsx(v,{type:C,className:B.button,initial:["hide",I],animate:I,variants:E,whileHover:"hover",whileTap:"pressed",...w,children:s.cloneElement(S,S.props,i.jsxs(i.Fragment,{children:[z,i.jsx("span",{className:B.content,children:S.props.children}),A]}))})}):i.jsx(x,{layoutSpeed:"3",layoutVariant:R,children:i.jsxs(a.m.button,{ref:N,type:C,className:B.button,initial:["hide",I],animate:I,variants:E,whileHover:"hover",whileTap:"pressed",...w,children:[z,i.jsx("span",{className:B.content,children:S}),A]})})})),C=s.forwardRef((function({palette:e,variant:o,size:n,iconVariant:c,loading:l,disableEffects:p,name:m,type:f="button",className:b,children:S,...v},j){const C=s.useRef(null);s.useImperativeHandle(j,(()=>C.current));const y=s.useMemo((()=>({button:t.getStyles({buttonVariant:o,buttonPalette:e,iconButtonSize:n,className:t.cx("uds-icon-button","uds-button","uds-ring","uds-hit-target",l&&"uds-button-loading",p&&"uds-button-without-effects",b)}),loading:"uds-button-icon start-content animate-spin",icon:"uds-button-icon start-content"})),[e,o,b,p,n,l]),w=a.useReducedMotion(),M=s.useMemo((()=>w?"smooth":"subtle"),[w]),N=s.useMemo((()=>{const{rest:t,hover:e,pressed:o}=h;return p?{rest:{},hover:{},pressed:{}}:{rest:t,hover:e,pressed:o}}),[p]);return i.jsx(x,{layoutSpeed:"3",layoutVariant:M,reducedMotion:p?"always":"user",children:i.jsx(a.m.button,{ref:C,type:f,className:y.button,initial:"icon",variants:N,whileHover:"hover",whileTap:"pressed",...v,children:i.jsxs(a.AnimatePresence,{initial:!1,mode:"popLayout",children:[l&&i.jsx(a.m.span,{variants:u,initial:"loading",animate:"loading",exit:"hide",children:i.jsx(t.Icon,{size:r.buttonIconSvgSize,name:g,variant:c,color:"current",className:y.loading})},"loading"),m&&!l&&i.jsx(a.m.span,{variants:d,initial:"icon",animate:"icon",exit:"hide",children:S||i.jsx(t.Icon,{size:r.buttonIconSvgSize,name:m,variant:c,color:"current",className:y.icon})},m.name)]})})})})),y=t.createSlot(),w=s.forwardRef((function({className:e,asChild:o,onPress:n,onClick:r=n,backgroundColor:a,borderRadius:s,borderTopStartRadius:c,borderTopEndRadius:l,borderBottomStartRadius:d,borderBottomEndRadius:u,borderColor:p,borderStartColor:m,borderEndColor:h,borderTopColor:f,borderBottomColor:g,borderWidth:b,borderVerticalWidth:x,borderHorizontalWidth:S,borderStartWidth:v,borderEndWidth:j,borderTopWidth:C,borderBottomWidth:w,alignContent:M,alignItems:N,alignSelf:V,flex:I,flexDirection:T,flexGrow:B,flexShrink:R,flexWrap:z,justifyContent:A,flexBasis:E,display:W,overflow:P,overflowX:_,overflowY:H,position:F,spacing:k,spacingHorizontal:G,spacingVertical:q,spacingBottom:U,spacingEnd:O,spacingStart:D,spacingTop:$,offset:L,offsetVertical:Y,offsetHorizontal:X,offsetBottom:J,offsetEnd:Q,offsetStart:K,offsetTop:Z,columnGap:tt,rowGap:et,...ot},nt){const rt=t.getStyles({backgroundColor:a,borderRadius:s,borderTopStartRadius:c,borderTopEndRadius:l,borderBottomStartRadius:d,borderBottomEndRadius:u,borderColor:p,borderStartColor:m,borderEndColor:h,borderTopColor:f,borderBottomColor:g,borderWidth:b,borderVerticalWidth:x,borderHorizontalWidth:S,borderStartWidth:v,borderEndWidth:j,borderTopWidth:C,borderBottomWidth:w,alignContent:M,alignItems:N,alignSelf:V,flex:I,flexDirection:T,flexGrow:B,flexShrink:R,flexWrap:z,justifyContent:A,flexBasis:E,display:W,overflow:P,overflowX:_,overflowY:H,position:F,spacing:k,spacingHorizontal:G,spacingVertical:q,spacingBottom:U,spacingEnd:O,spacingStart:D,spacingTop:$,offset:L,offsetVertical:Y,offsetHorizontal:X,offsetBottom:J,offsetEnd:Q,offsetStart:K,offsetTop:Z,columnGap:tt,rowGap:et,className:e}),it=o?y:"button";return i.jsx(it,{className:rt,ref:nt,onClick:r,...ot})}));
|
3
3
|
/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */exports.Button=j,exports.IconButton=C,exports.Pressable=w,exports.SpringMotionConfig=x;
|
package/dist/client/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
"use client";
|
2
|
-
import{createSlot as t,getStyles as o,cx as e,Icon as n}from"../chunk-HNDH4G6I.js";import{getMotionVar as r}from"../chunk-AJYO7N7R.js";import{motion as i}from"../chunk-QYZNWDRL.js";import{BUTTON_CSS_VAR_MAP as a}from"../chunk-PE2P7J44.js";import{buttonIconSvgSize as s}from"@yahoo/uds/fixtures";import{jsx as l,jsxs as c,Fragment as d}from"react/jsx-runtime";import{m as u,useReducedMotion as p,AnimatePresence as h,LazyMotion as m,MotionConfig as f}from"motion/react";import{forwardRef as b,useRef as g,useImperativeHandle as v,useMemo as
|
3
|
-
var x={scale:.7,opacity:0},V={scale:[.7,.7,1],opacity:[0,0,1],transition:{times:[0,.5,1]}},z={icon:V,hide:x,loading:x},W={loading:V,hide:x,icon:x},E=`var(${a.columnGap})`,I=`var(${a.iconSize})`,T={rest:{scale:`var(${a.effects.scale.rest})`},hover:{scale:`var(${a.effects.scale.hover})`},pressed:{scale:`var(${a.effects.scale.pressed})`},withoutIcon:{columnGap:"0px"},withIcon:{columnGap:E}},B={hide:{width:"0px",opacity:0,display:"none"},loading:{width:I,display:"flex",opacity:1},icon:{width:I,display:"flex",opacity:1}},R=({size:t,variant:o})=>{if("outline"===o)switch(t){case"sm":return l(d,{children:l("path",{fill:"currentColor",d:"M7.9 2.7a5.2 5.2 0 1 0 5.2 5.2h1.6a6.8 6.8 0 1 1-6.8-6.8.8.8 0 1 1 0 1.6"})});case"md":return l(d,{children:l("path",{fill:"currentColor",d:"M12 4a8 8 0 1 0 8 8h2c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2a1 1 0 1 1 0 2"})});case"lg":return l(d,{children:l("path",{fill:"currentColor",d:"M16.15 4.3C9.605 4.3 4.3 9.605 4.3 16.15S9.605 28 16.15 28 28 22.695 28 16.15h2.3c0 7.815-6.335 14.15-14.15 14.15S2 23.965 2 16.15 8.335 2 16.15 2a1.15 1.15 0 0 1 0 2.3"})})}if("fill"===o)switch(t){case"sm":return l(d,{children:l("path",{fill:"currentColor",d:"M8 2.9A5.1 5.1 0 1 0 13.1 8h1.8A6.9 6.9 0 1 1 8 1.1a.9.9 0 1 1 0 1.8"})});case"md":return l(d,{children:l("path",{fill:"currentColor",d:"M12.15 4.3A7.85 7.85 0 1 0 20 12.15h2.3c0 5.606-4.544 10.15-10.15 10.15S2 17.756 2 12.15 6.544 2 12.15 2a1.15 1.15 0 0 1 0 2.3"})});case"lg":return l(d,{children:l("path",{fill:"currentColor",d:"M16.35 4.7C9.916 4.7 4.7 9.916 4.7 16.35S9.916 28 16.35 28 28 22.784 28 16.35h2.7c0 7.925-6.425 14.35-14.35 14.35S2 24.275 2 16.35 8.425 2 16.35 2a1.35 1.35 0 1 1 0 2.7"})})}return l(d,{})},H=()=>import("../motionFeatures-PRT45UQH.js").then((({domAnimation:t})=>t));function k({reducedMotion:t="user",children:o,layoutVariant:e="subtle",layoutSpeed:n="3",colorVariant:a="smooth",colorSpeed:s="3"}){const c=i[e][n],d=i[a][s],[u,p]=S(c),[h,b]=S(d),g={variant:a,speed:s},v=r({...g,control:"stiffness"}),
|
2
|
+
import{createSlot as t,getStyles as o,cx as e,Icon as n}from"../chunk-HNDH4G6I.js";import{getMotionVar as r}from"../chunk-AJYO7N7R.js";import{motion as i}from"../chunk-QYZNWDRL.js";import{BUTTON_CSS_VAR_MAP as a}from"../chunk-PE2P7J44.js";import{buttonIconSvgSize as s}from"@yahoo/uds/fixtures";import{jsx as l,jsxs as c,Fragment as d}from"react/jsx-runtime";import{m as u,useReducedMotion as p,AnimatePresence as h,LazyMotion as m,MotionConfig as f}from"motion/react";import{forwardRef as b,useRef as g,useImperativeHandle as v,useMemo as y,isValidElement as C,cloneElement as w,useState as S,useEffect as N}from"react";/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */
|
3
|
+
var x={scale:.7,opacity:0},V={scale:[.7,.7,1],opacity:[0,0,1],transition:{times:[0,.5,1]}},z={icon:V,hide:x,loading:x},W={loading:V,hide:x,icon:x},E=`var(${a.columnGap})`,I=`var(${a.iconSize})`,T={rest:{scale:`var(${a.effects.scale.rest})`},hover:{scale:`var(${a.effects.scale.hover})`},pressed:{scale:`var(${a.effects.scale.pressed})`},withoutIcon:{columnGap:"0px"},withIcon:{columnGap:E}},B={hide:{width:"0px",opacity:0,display:"none"},loading:{width:I,display:"flex",opacity:1},icon:{width:I,display:"flex",opacity:1}},R=({size:t,variant:o})=>{if("outline"===o)switch(t){case"sm":return l(d,{children:l("path",{fill:"currentColor",d:"M7.9 2.7a5.2 5.2 0 1 0 5.2 5.2h1.6a6.8 6.8 0 1 1-6.8-6.8.8.8 0 1 1 0 1.6"})});case"md":return l(d,{children:l("path",{fill:"currentColor",d:"M12 4a8 8 0 1 0 8 8h2c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2a1 1 0 1 1 0 2"})});case"lg":return l(d,{children:l("path",{fill:"currentColor",d:"M16.15 4.3C9.605 4.3 4.3 9.605 4.3 16.15S9.605 28 16.15 28 28 22.695 28 16.15h2.3c0 7.815-6.335 14.15-14.15 14.15S2 23.965 2 16.15 8.335 2 16.15 2a1.15 1.15 0 0 1 0 2.3"})})}if("fill"===o)switch(t){case"sm":return l(d,{children:l("path",{fill:"currentColor",d:"M8 2.9A5.1 5.1 0 1 0 13.1 8h1.8A6.9 6.9 0 1 1 8 1.1a.9.9 0 1 1 0 1.8"})});case"md":return l(d,{children:l("path",{fill:"currentColor",d:"M12.15 4.3A7.85 7.85 0 1 0 20 12.15h2.3c0 5.606-4.544 10.15-10.15 10.15S2 17.756 2 12.15 6.544 2 12.15 2a1.15 1.15 0 0 1 0 2.3"})});case"lg":return l(d,{children:l("path",{fill:"currentColor",d:"M16.35 4.7C9.916 4.7 4.7 9.916 4.7 16.35S9.916 28 16.35 28 28 22.784 28 16.35h2.7c0 7.925-6.425 14.35-14.35 14.35S2 24.275 2 16.35 8.425 2 16.35 2a1.35 1.35 0 1 1 0 2.7"})})}return l(d,{})},H=()=>import("../motionFeatures-PRT45UQH.js").then((({domAnimation:t})=>t));function k({reducedMotion:t="user",children:o,layoutVariant:e="subtle",layoutSpeed:n="3",colorVariant:a="smooth",colorSpeed:s="3"}){const c=i[e][n],d=i[a][s],[u,p]=S(c),[h,b]=S(d),g={variant:a,speed:s},v=r({...g,control:"stiffness"}),C=r({...g,control:"damping"}),w={variant:e,speed:n},x=r({...w,control:"stiffness"}),V=r({...w,control:"damping"});N((()=>{const t=getComputedStyle(document.documentElement),o={damping:Number(t.getPropertyValue(V)),stiffness:Number(t.getPropertyValue(x))},e={damping:Number(t.getPropertyValue(C)),stiffness:Number(t.getPropertyValue(v))};p(o),b(e)}),[C,v,V,x]);const z=y((()=>({type:"spring",mass:1,...u,layout:u,opacity:h,color:h,borderColor:h,backgroundColor:h})),[h,u]);return l(m,{features:H,strict:!0,children:l(f,{transition:z,reducedMotion:t,children:o})})}var G=t(),P=u.create(G),M=b((function({palette:t,variant:r,size:i,startIcon:a,endIcon:m,iconVariant:f,loading:b,disableEffects:S,children:N,asChild:x,type:V="button",className:E,...I},H){const G=g(null);v(H,(()=>G.current));const M=m?"icon":"hide",j=(({startIcon:t,endIcon:o,loading:e})=>t||o||e?"withIcon":"withoutIcon")({startIcon:a,endIcon:m,loading:b}),A=(({loading:t,startIcon:o})=>t?"loading":o?"icon":"hide")({loading:b,startIcon:a}),$={button:o({buttonSize:i,buttonVariant:r,buttonPalette:t,className:e("uds-button","uds-ring","uds-hit-target",b&&"uds-button-loading",S&&"uds-button-without-effects","withIcon"===j&&"uds-button-with-gap",E)}),content:"uds-button-content truncate",iconContainer:"uds-button-icon-container flex overflow-clip",loading:"uds-button-icon start-content animate-spin",start:"uds-button-icon start-content",end:"uds-button-icon end-content"},D=p()?"smooth":"subtle",L=y((()=>l(u.span,{className:$.iconContainer,initial:!1,variants:B,animate:A,children:c(h,{initial:!1,mode:"popLayout",children:[b&&l(u.span,{variants:W,initial:"hide",animate:"loading",exit:"hide",children:l(n,{size:s,name:R,variant:f,color:"current",className:$.loading})},"loading"),a&&!b&&l(u.span,{variants:z,initial:"hide",animate:"icon",exit:"hide",children:l(n,{size:s,name:a,variant:f,color:"current",className:$.start})},a.name)]})})),[$.iconContainer,$.loading,$.start,A,b,f,a]),Y=y((()=>l(u.span,{className:$.iconContainer,initial:!1,variants:B,animate:M,children:l(h,{initial:!1,mode:"popLayout",children:m&&l(u.span,{variants:z,initial:"hide",animate:"icon",exit:"hide",children:l(n,{size:s,name:m,variant:f,color:"current",className:$.start})},m.name)})})),[$.iconContainer,$.start,m,M,f]),J=y((()=>S?{...T,rest:{},hover:{},pressed:{}}:T),[S]);return x&&C(N)?l(k,{layoutSpeed:"3",layoutVariant:D,children:l(P,{type:V,className:$.button,initial:["hide",j],animate:j,variants:J,whileHover:"hover",whileTap:"pressed",...I,children:w(N,N.props,c(d,{children:[L,l("span",{className:$.content,children:N.props.children}),Y]}))})}):l(k,{layoutSpeed:"3",layoutVariant:D,children:c(u.button,{ref:G,type:V,className:$.button,initial:["hide",j],animate:j,variants:J,whileHover:"hover",whileTap:"pressed",...I,children:[L,l("span",{className:$.content,children:N}),Y]})})})),j=b((function({palette:t,variant:r,size:i,iconVariant:a,loading:d,disableEffects:m,name:f,type:b="button",className:C,children:w,...S},N){const x=g(null);v(N,(()=>x.current));const V=y((()=>({button:o({buttonVariant:r,buttonPalette:t,iconButtonSize:i,className:e("uds-icon-button","uds-button","uds-ring","uds-hit-target",d&&"uds-button-loading",m&&"uds-button-without-effects",C)}),loading:"uds-button-icon start-content animate-spin",icon:"uds-button-icon start-content"})),[t,r,C,m,i,d]),E=p(),I=y((()=>E?"smooth":"subtle"),[E]),B=y((()=>{const{rest:t,hover:o,pressed:e}=T;return m?{rest:{},hover:{},pressed:{}}:{rest:t,hover:o,pressed:e}}),[m]);return l(k,{layoutSpeed:"3",layoutVariant:I,reducedMotion:m?"always":"user",children:l(u.button,{ref:x,type:b,className:V.button,initial:"icon",variants:B,whileHover:"hover",whileTap:"pressed",...S,children:c(h,{initial:!1,mode:"popLayout",children:[d&&l(u.span,{variants:W,initial:"loading",animate:"loading",exit:"hide",children:l(n,{size:s,name:R,variant:a,color:"current",className:V.loading})},"loading"),f&&!d&&l(u.span,{variants:z,initial:"icon",animate:"icon",exit:"hide",children:w||l(n,{size:s,name:f,variant:a,color:"current",className:V.icon})},f.name)]})})})})),A=t(),$=b((function({className:t,asChild:e,onPress:n,onClick:r=n,backgroundColor:i,borderRadius:a,borderTopStartRadius:s,borderTopEndRadius:c,borderBottomStartRadius:d,borderBottomEndRadius:u,borderColor:p,borderStartColor:h,borderEndColor:m,borderTopColor:f,borderBottomColor:b,borderWidth:g,borderVerticalWidth:v,borderHorizontalWidth:y,borderStartWidth:C,borderEndWidth:w,borderTopWidth:S,borderBottomWidth:N,alignContent:x,alignItems:V,alignSelf:z,flex:W,flexDirection:E,flexGrow:I,flexShrink:T,flexWrap:B,justifyContent:R,flexBasis:H,display:k,overflow:G,overflowX:P,overflowY:M,position:j,spacing:$,spacingHorizontal:D,spacingVertical:L,spacingBottom:Y,spacingEnd:J,spacingStart:Q,spacingTop:X,offset:F,offsetVertical:O,offsetHorizontal:U,offsetBottom:Z,offsetEnd:q,offsetStart:K,offsetTop:_,columnGap:tt,rowGap:ot,...et},nt){const rt=o({backgroundColor:i,borderRadius:a,borderTopStartRadius:s,borderTopEndRadius:c,borderBottomStartRadius:d,borderBottomEndRadius:u,borderColor:p,borderStartColor:h,borderEndColor:m,borderTopColor:f,borderBottomColor:b,borderWidth:g,borderVerticalWidth:v,borderHorizontalWidth:y,borderStartWidth:C,borderEndWidth:w,borderTopWidth:S,borderBottomWidth:N,alignContent:x,alignItems:V,alignSelf:z,flex:W,flexDirection:E,flexGrow:I,flexShrink:T,flexWrap:B,justifyContent:R,flexBasis:H,display:k,overflow:G,overflowX:P,overflowY:M,position:j,spacing:$,spacingHorizontal:D,spacingVertical:L,spacingBottom:Y,spacingEnd:J,spacingStart:Q,spacingTop:X,offset:F,offsetVertical:O,offsetHorizontal:U,offsetBottom:Z,offsetEnd:q,offsetStart:K,offsetTop:_,columnGap:tt,rowGap:ot,className:t});return l(e?A:"button",{className:rt,ref:nt,onClick:r,...et})}));
|
4
4
|
/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */export{M as Button,j as IconButton,$ as Pressable,k as SpringMotionConfig};
|