Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tooltip component #2490

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "BB1+9pvHl5G2iudcAUaVWy8kprwT1nfp3DxPk4Ijct8=",
"shasum": "EmIaWoL8nod1rTuXeLuMVRItSn4yygM0QwF0575u4pI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "8D4ebYpXIanxifZIoDx/4RRIiUpV0kNXXEAnV8dIyBY=",
"shasum": "3MsLr8jtTbv2bEGnK4qfD6OhE16rtXctYYW8LDjbL1U=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "NFKbyUcvtcg4cjFsScuZ9K5U7wcQ2vWFVkWBC/vdeus=",
"shasum": "93dNm72NPNodS7UnTsxbAbxEgr81msGHGlBnxasd4hA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "wJxHirjCewTn0AEH80KiNl5DGm+I0S0TU0KhNb0QGW0=",
"shasum": "rSs7zVVuekYGpvFT7xMmVHUwuJVmrYtJ1TpZiLln4+M=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "VkDbVKN11iYQXds2IaJ8gM+bUVh9w+R3I/3LftXPHAk=",
"shasum": "Lw+o0xSBK3RLoxMPA3VV9pcJts7slKwlw/FLH2os7Rs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "rttj1fYEAaln9fq0X+4fUnpQpgzPBCVlA/gX72aWhNU=",
"shasum": "suKnTPMwveOjTGAh5LZhnEflYUfoEclrm7MEQMekFSc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Tiu7E0Za1n0Erj/hY90kN2WBTDBQLqe0ZB5g8PX9Uo0=",
"shasum": "sVbh3wlE3T2kxAgUvCwBk7aBxmJGwyMYojvVamglYyc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "9cPZYGIWcu53Dhxf14K4kTSpuqhNl+GHDVH9HU35yAI=",
"shasum": "iha5MN97D891xWP1typXrc0OHZAyRZQRQgpbrYtrub0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "z3LErF1RXhS01ErXrJSIWXqvjP44vm+TfHVjGoexxuY=",
"shasum": "D7hWiwyKT0CVTINjQZvUDKk3kj8mhngADM1bSKpp/js=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "SbuJLsNB4S4tzkrq2SMX1JwexcdrAIZ0vfBhq/5mn18=",
"shasum": "LtCe3Khdid7ufThHQQEJb1OOrO72iD5uyK7B2DQRi4c=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "6P5WA3V2Sw/lc2VGNaXsHNThlglFhWW2eKm+v42F+ak=",
"shasum": "zuc2MclbVUnpaFuvx3H1HwYsJymvVsfJsBq1wrSEElQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-file/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "x3U2v0ix/dIo1fgxbFC0JEjA749mW9eS5hA1Z/uPn3s=",
"shasum": "eiyB374KOWchfjaUeqCmN5wpKhBNb1yNiTobgJMJG6I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "0y8qGup1KW+sFpC3wYNBZ90YJYnrBRL0fldN7ZKHJE8=",
"shasum": "RZyBT/FIDK7GtFwshSGOYXczOrVteUn4H5DS+ZbgsbU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "k0XiC0mJ6Zw9sudmKH8j7fjnPc0TlsNndtf58KBdPgA=",
"shasum": "xcXlfc8BGEa4XLJ9uGTWNveYej9QikFZn4nQ9NdxlsM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "ZrmkKMXWu90H7Ea3O1aDTlAsv10mt2W3qK6U/Bu6Ef4=",
"shasum": "Q5Uq4v0Mmevehh0PIJvusWEHFH+ITLysyyY+17JUsK0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "zd9v3UmiESa6JD1Pc9uenZ2bH+pfqqN3LgryYf4PkPk=",
"shasum": "Xr795QUI4U++cOYMm9FVpXVarO1mjIDSjKF+QQF2UZI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "LKU/dRxxeMKb9yUzzDwhP1sVTcqqHSmE3DDspw4i4vw=",
"shasum": "1E0eIMXYC+twPeiAqcuRRPu5fxf5FD4f1dV08VUGwK0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/json-rpc/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Q4i6cNhFqTmQq+LZqkpdtA0bzP//XwU3CN+9SEi5HV4=",
"shasum": "yJziKY8cECUlDoxP8VFfsH2oEhPFn0ZWKFbYPkjujpM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/jsx/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "qTxO+zikJeylsmKgvGuKtrPOgXOOARr9+agGHy6jRLw=",
"shasum": "hMfqZ8Nrz8lpBhxOdId3kaND5WZrwxQd5Sx+KxjY0K8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "TwzD1ldZMXP1G5Xh0imRnANPmfWcWWxwMWfnD89fTmU=",
"shasum": "oLzmeZcE9qxgf+jQpA9OiqFpuf2dfBT3Y9nED5z6nWs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "DOffnM76/Axe+pctk0eR8KYfAe8H8Mz5FvWk/Gdd9c4=",
"shasum": "Se1CTGg3ExDVv9SNZ6oaAE4ADWDYiET+Y4OW7N+P8xE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "bynm+cOfGCGK+IqcbE3WjuHMXaK94Wngz46ZiRCTA9o=",
"shasum": "wwwWEa/1xj0n+1uUmkCs7tUYvDcbfoDYQKOXfJfPJuY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "joVkDlMRDqCfZ+3Mx7ZnKeLWPYHmEiTic47gDYsVDo0=",
"shasum": "6cLHi5YriTK9gqn9cOx6CJavruqrkhRLaX/Ckgy6s4s=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "52mermVIKcN8PYT0buRjmsHBTxCMsLd2YoT+sxm1qsI=",
"shasum": "UPKvEsDiuFKi9GAm42/PaCXR9iy4yf7sHVF4dl4Sc84=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "1R21n92RzfVfQxjScRON3cOxSk+Ez5u3O/i9fKuPs/o=",
"shasum": "Vx4Qu2N6v706JMplTl9yZjjY+E1SzH3E4kRvPS6aO9c=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "plbQA+egc3NMftFNlJ7ONX09tY5vTL3sUm/VcxqgFfM=",
"shasum": "tRru7Bgry6u3eoboCgkXy5pAYrEDVhVVZg0CcTI8K88=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "wJz5xT13dghX5Z/tN0C2i43fdloxZg0yy2EQVwt0DbA=",
"shasum": "+sNj2KKAA6mES8j1X544gahfD1EVxN7NUruGHug7PAw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/wasm/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "hLt7f+ezZ+X7hhYNQsVaKaRxSBTL2sCoCfj0fnMwefk=",
"shasum": "wrvKQQKLWFp3fD4gVxAUd/g89JCMk3dYCTh/jTvmrl0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "UPthnrafIh2vEr2kkDXb5l3HBcgke2dQg5RoKygbGEs=",
"shasum": "g2mArhUUuqRTQKapIisLg0ZcjmrOuDa+9K+LHyUBdJ8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
46 changes: 46 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Tooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createSnapComponent } from '../component';
import type { StandardFormattingElement } from './formatting';
import type { ImageElement } from './Image';
import type { LinkElement } from './Link';
import type { TextElement } from './Text';

export type TooltipChildren =
| TextElement
| StandardFormattingElement
| LinkElement
| ImageElement
| null;

/**
* The props of the {@link Tooltip} component.
*
* @property children - The children of the box.
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved
* @property content - The text to display in the tooltip.
*/
export type TooltipProps = {
children: TooltipChildren;
content: TextElement | StandardFormattingElement | LinkElement | string;
};

const TYPE = 'Tooltip';

/**
* A tooltip component, which is used to display text in a tooltip.
*
* @param props - The props of the component.
* @param props.children - The children of the tooltip.
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved
* @param props.content - The text to display in the tooltip.
* @returns A tooltip element.
* @example
* <Tooltip content={<Text>foo</Text>}>
* <Text>Hello world!</Text>
* </Tooltip>
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved
*/
export const Tooltip = createSnapComponent<TooltipProps, typeof TYPE>(TYPE);

/**
* A box element.
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved
*
* @see Tooltip
*/
export type TooltipElement = ReturnType<typeof Tooltip>;
5 changes: 4 additions & 1 deletion packages/snaps-sdk/src/jsx/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { LinkElement } from './Link';
import type { RowElement } from './Row';
import type { SpinnerElement } from './Spinner';
import type { TextElement } from './Text';
import type { TooltipElement } from './Tooltip';
import type { ValueElement } from './Value';

export * from './form';
Expand All @@ -25,6 +26,7 @@ export * from './Link';
export * from './Row';
export * from './Spinner';
export * from './Text';
export * from './Tooltip';

/**
* A built-in JSX element, which can be used in a Snap user interface.
Expand All @@ -42,4 +44,5 @@ export type JSXElement =
| LinkElement
| RowElement
| SpinnerElement
| TextElement;
| TextElement
| TooltipElement;
41 changes: 41 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Row,
Spinner,
Text,
Tooltip,
Value,
FileInput,
} from './components';
Expand Down Expand Up @@ -47,6 +48,7 @@ import {
SpinnerStruct,
StringElementStruct,
TextStruct,
TooltipStruct,
ValueStruct,
} from './validation';

Expand Down Expand Up @@ -721,6 +723,45 @@ describe('TextStruct', () => {
});
});

describe('TooltipStruct', () => {
it.each([
<Tooltip content="foo">
<Text>bar</Text>
</Tooltip>,
<Tooltip content={<Text>foo</Text>}>
<Bold>bar</Bold>
</Tooltip>,
])(`validates a tooltip element`, (value) => {
expect(is(value, TooltipStruct)).toBe(true);
});

it.each([
'foo',
42,
null,
undefined,
{},
[],
// @ts-expect-error - Invalid props.
<Tooltip />,
// @ts-expect-error - Invalid props.
<Tooltip foo="bar">foo</Tooltip>,
<Tooltip content={<Copyable value="bar" />}>
<Text>foo</Text>
</Tooltip>,
<Box>
<Tooltip content={'foo'}>
<Text>foo</Text>
</Tooltip>
</Box>,
<Row label="label">
<Image src="<svg />" alt="alt" />
</Row>,
])('does not validate "%p"', (value) => {
expect(is(value, TooltipStruct)).toBe(false);
});
});

describe('RowStruct', () => {
it.each([
<Row label="label">
Expand Down
Loading
Loading