Skip to content

Commit 8d11258

Browse files
committed
start working on notifications
1 parent 6e4b373 commit 8d11258

File tree

7 files changed

+47
-38
lines changed

7 files changed

+47
-38
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"@clack/prompts": "^0.11.0",
4444
"@heroicons/react": "^2.2.0",
4545
"@minify-html/node": "^0.16.4",
46-
"@node-core/rehype-shiki": "~1.0.1-334d42dfdaf80b36b24a1982807367727cf52ccd",
47-
"@node-core/ui-components": "~1.0.1-a356572cf397450a3eeeb973d6fe6d6803a24059",
46+
"@node-core/rehype-shiki": "1.0.1-334d42dfdaf80b36b24a1982807367727cf52ccd",
47+
"@node-core/ui-components": "1.0.1-4d3182b1699ee0824d1632746808071522f65023",
4848
"@orama/orama": "^3.1.10",
4949
"@orama/plugin-data-persistence": "^3.1.10",
5050
"@orama/react-components": "^0.8.1",

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,18 @@ const processEntry = entry => {
211211
*/
212212
const createDocumentLayout = (entries, sideBarProps, metaBarProps) => {
213213
return createTree('root', [
214-
createJSXElement(JSX_IMPORTS.NavBar.name),
215-
createJSXElement(JSX_IMPORTS.Article.name, {
214+
createJSXElement(JSX_IMPORTS.NotificationProvider.name, {
216215
children: [
217-
createJSXElement(JSX_IMPORTS.SideBar.name, sideBarProps),
218-
createElement('div', [
219-
createElement('main', entries.map(processEntry)),
220-
createJSXElement(JSX_IMPORTS.MetaBar.name, metaBarProps),
221-
]),
216+
createJSXElement(JSX_IMPORTS.NavBar.name),
217+
createJSXElement(JSX_IMPORTS.Article.name, {
218+
children: [
219+
createJSXElement(JSX_IMPORTS.SideBar.name, sideBarProps),
220+
createElement('div', [
221+
createElement('main', entries.map(processEntry)),
222+
createJSXElement(JSX_IMPORTS.MetaBar.name, metaBarProps),
223+
]),
224+
],
225+
}),
222226
],
223227
}),
224228
]);

src/generators/web/build/generate.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export default () => {
2828
// Create base imports from JSX_IMPORTS configuration
2929
// TODO(@avivkeller): A lot of these imports aren't interactive (i.e. the MetaBar),
3030
// so it would be nice to not pass them to the client at all.
31-
const baseImports = Object.values(JSX_IMPORTS).map(({ name, source }) =>
32-
createImportDeclaration(name, source)
31+
const baseImports = Object.values(JSX_IMPORTS).map(
32+
({ name, source, default: useDefault = true }) =>
33+
createImportDeclaration(name, source, useDefault)
3334
);
3435

3536
/**

src/generators/web/constants.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ export const JSX_IMPORTS = {
4343
name: 'ArrowUpRightIcon',
4444
source: '@heroicons/react/24/solid/ArrowUpRightIcon',
4545
},
46+
NotificationProvider: {
47+
name: 'NotificationProvider',
48+
default: false,
49+
source: '@node-core/ui-components/Providers/NotificationProvider',
50+
},
4651
};
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { CodeBracketIcon } from '@heroicons/react/24/outline';
12
import BaseCodeBox from '@node-core/ui-components/Common/BaseCodeBox';
2-
import { useState } from 'react';
3+
import styles from '@node-core/ui-components/Common/BaseCodeBox/index.module.css';
4+
import { useNotification } from '@node-core/ui-components/Providers/NotificationProvider';
35

46
import { STATIC_DATA } from '../constants.mjs';
57

@@ -17,40 +19,34 @@ export const getLanguageDisplayName = language => {
1719
return entry?.[1] ?? language.toLowerCase();
1820
};
1921

20-
/**
21-
* @typedef CodeBoxProps
22-
* @property {string} [className] - CSS class with language info
23-
*/
24-
25-
/**
26-
* Code box component with syntax highlighting and copy functionality
27-
* @param {import('react').PropsWithChildren<CodeBoxProps>} props
28-
*/
22+
/** @param {import('react').PropsWithChildren<{ className: string }>} props */
2923
export default ({ className, ...props }) => {
3024
const matches = className?.match(/language-(?<language>[a-zA-Z]+)/);
3125
const language = matches?.groups?.language ?? '';
32-
const [copyText, setCopyText] = useState('Copy to clipboard');
3326

34-
/**
35-
* Copy text to clipboard and show feedback
36-
* @param {string} text - Text to copy
37-
*/
38-
const handleCopy = async text => {
27+
const notify = useNotification();
28+
29+
const onCopy = async text => {
3930
await navigator.clipboard.writeText(text);
4031

41-
setCopyText('Copied to clipboard!');
42-
setTimeout(() => {
43-
setCopyText('Copy to clipboard');
44-
}, 500);
32+
notify({
33+
duration: 300,
34+
message: (
35+
<div className="flex items-center gap-3">
36+
<CodeBracketIcon className={styles.icon} />
37+
Copied to clipboard
38+
</div>
39+
),
40+
});
4541
};
4642

4743
return (
4844
<BaseCodeBox
4945
as={'a'}
50-
onCopy={handleCopy}
46+
onCopy={onCopy}
5147
language={getLanguageDisplayName(language)}
5248
{...props}
53-
buttonText={copyText}
49+
buttonText={'Copy to clipboard'}
5450
/>
5551
);
5652
};

src/generators/web/ui/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sideEffects": false
3+
}

0 commit comments

Comments
 (0)