diff --git a/package.json b/package.json index cd4f9eb0..dfc6ba0f 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "react-sortablejs": "^6.1.1", "sortablejs": "^1.15.0", "ua-parser-js": "^1.0.2", + "use-onclickoutside": "^0.4.0", "uuid": "^8.3.2", "zod": "^3.15.1", "zustand": "4.0.0-rc.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32f9aa0b..855acc3a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,7 @@ specifiers: tailwindcss: ^3.0.24 typescript: ^4.5.5 ua-parser-js: ^1.0.2 + use-onclickoutside: ^0.4.0 uuid: ^8.3.2 zod: ^3.15.1 zustand: 4.0.0-rc.1 @@ -99,6 +100,7 @@ dependencies: react-sortablejs: 6.1.1_kjz72dk5lh6hp4ogspefhm7r2u sortablejs: 1.15.0 ua-parser-js: 1.0.2 + use-onclickoutside: 0.4.0_7cpxmzzodpxnolj5zcc5cr63ji uuid: 8.3.2 zod: 3.15.1 zustand: 4.0.0-rc.1_react@18.1.0 @@ -1014,6 +1016,10 @@ packages: picomatch: 2.3.1 dev: true + /are-passive-events-supported/1.1.1: + resolution: {integrity: sha512-5wnvlvB/dTbfrCvJ027Y4L4gW/6Mwoy1uFSavney0YO++GU+0e/flnjiBBwH+1kh7xNCgCOGvmJC3s32joYbww==} + dev: false + /arg/5.0.1: resolution: {integrity: sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==} dev: true @@ -3223,6 +3229,45 @@ packages: resolution: {integrity: sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==} dev: false + /use-isomorphic-layout-effect/1.1.2_7cpxmzzodpxnolj5zcc5cr63ji: + resolution: {integrity: sha512-49L8yCO3iGT/ZF9QttjwLF/ZD9Iwto5LnH5LmEdk/6cFmXddqi2ulF0edxTwjj+7mqvpVVGQWvbXZdn32wRSHA==} + peerDependencies: + '@types/react': '*' + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + '@types/react': + optional: true + dependencies: + '@types/react': 18.0.9 + react: 18.1.0 + dev: false + + /use-latest/1.2.1_7cpxmzzodpxnolj5zcc5cr63ji: + resolution: {integrity: sha512-xA+AVm/Wlg3e2P/JiItTziwS7FK92LWrDB0p+hgXloIMuVCeJJ8v6f0eeHyPZaJrM+usM1FkFfbNCrJGs8A/zw==} + peerDependencies: + '@types/react': '*' + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + '@types/react': + optional: true + dependencies: + '@types/react': 18.0.9 + react: 18.1.0 + use-isomorphic-layout-effect: 1.1.2_7cpxmzzodpxnolj5zcc5cr63ji + dev: false + + /use-onclickoutside/0.4.0_7cpxmzzodpxnolj5zcc5cr63ji: + resolution: {integrity: sha512-lg1U+V8SaCfemgBs5dg+cfEOzjuwVS9ATH0VMLSBHI6R11tbfmiKci1lg6pjwXr1sj95XWd2+5EbffJEAPdkJQ==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 + dependencies: + are-passive-events-supported: 1.1.1 + react: 18.1.0 + use-latest: 1.2.1_7cpxmzzodpxnolj5zcc5cr63ji + transitivePeerDependencies: + - '@types/react' + dev: false + /use-sync-external-store/1.1.0_react@18.1.0: resolution: {integrity: sha512-SEnieB2FPKEVne66NpXPd1Np4R1lTNKfjuy3XdIoPQKYBAFdzbzSZlSn1KJZUiihQLQC5Znot4SBz1EOTBwQAQ==} peerDependencies: diff --git a/src/components/dashboard/PublishButton.tsx b/src/components/dashboard/PublishButton.tsx new file mode 100644 index 00000000..3a0c9eb9 --- /dev/null +++ b/src/components/dashboard/PublishButton.tsx @@ -0,0 +1,65 @@ +import { useRef, useState } from "react" +import useOnClickOutside from "use-onclickoutside" + +import { Button, ButtonGroup } from "../ui/Button" + +export const PublishButton: React.FC<{ + save: (published: boolean) => void + published: boolean +}> = ({ save, published }) => { + const [showDropdown, setShowDropdown] = useState(false) + const dropdownRef = useRef(null) + const triggerRef = useRef(null) + + useOnClickOutside(dropdownRef, (e) => { + if (triggerRef.current?.contains(e.target as any)) return + setShowDropdown(false) + }) + + return ( +
+ + + + + {showDropdown && ( +
+
+ {published ? ( + + ) : ( + + )} +
+
+ )} +
+ ) +} diff --git a/src/components/ui/Button.tsx b/src/components/ui/Button.tsx index 4bbf67cb..38e3e3bc 100644 --- a/src/components/ui/Button.tsx +++ b/src/components/ui/Button.tsx @@ -1,32 +1,47 @@ import React from "react" import clsx from "clsx" -export const Button: React.FC< - React.ButtonHTMLAttributes & { - isLoading?: boolean - isBlock?: boolean - isDisabled?: boolean - variant?: "primary" | "secondary" | "text" - variantColor?: "green" | "red" | "gray" - size?: "sm" - rounded?: "full" | "lg" - } -> = ({ - type, +export const ButtonGroup: React.FC<{ children: React.ReactNode }> = ({ children, - className, - isLoading, - isDisabled, - isBlock, - variant, - variantColor, - size, - rounded, - ...props }) => { + return
{children}
+} + +type ButtonProps = { + isLoading?: boolean + isBlock?: boolean + isDisabled?: boolean + isAutoWidth?: boolean + variant?: "primary" | "secondary" | "text" + variantColor?: "green" | "red" | "gray" + size?: "sm" + rounded?: "full" | "lg" +} + +export const Button = React.forwardRef< + HTMLButtonElement, + React.ButtonHTMLAttributes & ButtonProps +>(function Button( + { + type, + children, + className, + isLoading, + isDisabled, + isBlock, + variant, + variantColor, + size, + rounded, + isAutoWidth, + ...props + }, + ref +) { return ( - - - ) - }} - - +
@@ -241,7 +202,23 @@ export default function SubdomainEditor() {
-
+
+
+ { + updateValue("publishedAt", e.target.value) + }} + help={`This ${ + isPost ? "post" : "page" + } will be accesisble from this time`} + /> +
updateValue("slug", e.target.value)} + help={ + <> + {values.slug && ( + <> + This {isPost ? "post" : "page"} will be accessible at{" "} + + {getSiteLink({ subdomain, noProtocol: true })}/ + {values.slug} + + + )} + + } /> - {values.slug && ( -
- This {isPost ? "post" : "page"} will be accessible at{" "} - - {getSiteLink({ subdomain, noProtocol: true })}/{values.slug} - -
- )}