Skip to content

Commit

Permalink
feat: edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Sep 17, 2024
1 parent 6641e7d commit 0848125
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@glocurrency/ui`

React components

---

## Install

```bash
$ pnpm add @glocurrency/ui
```

## Authors

- [Ivan Stasiuk](https://github.com/brokeyourbike) | [Twitter](https://twitter.com/brokeyourbike) | [LinkedIn](https://www.linkedin.com/in/brokeyourbike) | [stasi.uk](https://stasi.uk)
8 changes: 6 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@glocurrency/ui",
"description": "React components",
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"engines": {
"node": ">=20.x"
Expand Down Expand Up @@ -56,10 +56,14 @@
"@glocurrency/time": ">=0.0",
"@glocurrency/use-get": ">=0.0",
"@shopify/polaris": ">=13.0",
"@shopify/polaris-icons": ">=9.0",
"query-string": ">=9.0",
"next": ">=14.0",
"react": ">=18.0",
"react-dom": ">=18.0",
"react-syntax-highlighter": ">=15.0"
"react-syntax-highlighter": ">=15.0",
"react-hot-toast": ">=2.0",
"react-use-clipboard": ">=1.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.5.0",
Expand Down
51 changes: 51 additions & 0 deletions packages/ui/src/components/EditPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useMemo, type ReactNode } from 'react'
import { useRouter } from 'next/router'
import { MenuActionDescriptor, Page } from '@shopify/polaris'
import { ShareIcon } from '@shopify/polaris-icons'
import useClipboard from 'react-use-clipboard'
import toast from 'react-hot-toast'

export const EditPage = ({
title,
children,
showShareButton,
}: {
title: string
children: ReactNode
showShareButton?: boolean
}) => {
const router = useRouter()
const [_, setCopied] = useClipboard(
`${process.env['NEXT_PUBLIC_BASE_PATH']}${router.asPath}`
)

const actions = useMemo(() => {
const items: MenuActionDescriptor[] = []

if (showShareButton) {
items.push({
icon: ShareIcon,
content: 'Share',
onAction: () => {
setCopied()
toast.success('URL copied to clipboard')
},
})
}

return items
}, [showShareButton, setCopied])

return (
<Page
title={title}
backAction={{
content: 'Back',
onAction: () => router.back(),
}}
secondaryActions={actions}
>
{children}
</Page>
)
}
1 change: 1 addition & 0 deletions packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { HighlightJson } from './HighlightJson'
export { LoadingCard } from './LoadingCard'
export { Timeline } from './Timeline'
export { EditPage } from './EditPage'

0 comments on commit 0848125

Please sign in to comment.