mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-27 20:16:28 -08:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <[email protected]>
371 lines
11 KiB
TypeScript
371 lines
11 KiB
TypeScript
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
|
import cx from "classnames"
|
|
import React, { Component, ComponentProps, FormEvent } from "react"
|
|
import X from "src/assets/icons/x.svg?react"
|
|
import Button from "src/ui/button"
|
|
import PortalContainerContext from "src/ui/portal-container-context"
|
|
import { isObject } from "src/utils/util"
|
|
|
|
type ButtonProp = boolean | string | Partial<ComponentProps<typeof Button>>
|
|
|
|
/**
|
|
* ControlledDialogProps are common props required for dialog components with
|
|
* controlled state. Since Dialog components frequently expose these props to
|
|
* their callers, we've consolidated them here for easy access.
|
|
*/
|
|
export type ControlledDialogProps = {
|
|
/**
|
|
* open is a boolean that controls whether the dialog is open or not.
|
|
*/
|
|
open: boolean
|
|
/**
|
|
* onOpenChange is a callback that is called when the open state of the dialog
|
|
* changes.
|
|
*/
|
|
onOpenChange: (open: boolean) => void
|
|
}
|
|
|
|
type PointerDownOutsideEvent = CustomEvent<{
|
|
originalEvent: PointerEvent
|
|
}>
|
|
|
|
type Props = {
|
|
className?: string
|
|
/**
|
|
* title is the title of the dialog, shown at the top.
|
|
*/
|
|
title: string
|
|
/**
|
|
* titleSuffixDecoration is added to the title, but is not part of the ARIA label for
|
|
* the dialog. This is useful for adding a badge or other non-semantic
|
|
* information to the title.
|
|
*/
|
|
titleSuffixDecoration?: React.ReactNode
|
|
/**
|
|
* trigger is an element to use as a trigger for a dialog. Using trigger is
|
|
* preferrable to using `open` for managing state, as it allows for better
|
|
* focus management for screen readers.
|
|
*/
|
|
trigger?: React.ReactNode
|
|
/**
|
|
* children is the content of the dialog.
|
|
*/
|
|
children: React.ReactNode
|
|
/**
|
|
* defaultOpen is the default state of the dialog. This is meant to be used for
|
|
* uncontrolled dialogs, and should not be combined with `open` or
|
|
* `onOpenChange`.
|
|
*/
|
|
defaultOpen?: boolean
|
|
/**
|
|
* restoreFocus determines whether the dialog returns focus to the trigger
|
|
* element or not after closing.
|
|
*/
|
|
restoreFocus?: boolean
|
|
onPointerDownOutside?: (e: PointerDownOutsideEvent) => void
|
|
} & Partial<ControlledDialogProps>
|
|
|
|
const dialogOverlay =
|
|
"fixed overflow-y-auto inset-0 py-8 z-10 bg-gray-900 bg-opacity-[0.07]"
|
|
const dialogWindow = cx(
|
|
"bg-white rounded-lg relative max-w-lg min-w-[19rem] w-[97%] shadow-dialog",
|
|
"p-4 md:p-6 my-8 mx-auto",
|
|
// We use `transform-gpu` here to force the browser to put the dialog on its
|
|
// own layer. This helps fix some weird artifacting bugs in Safari caused by
|
|
// box-shadows. See: https://github.com/tailscale/corp/issues/12270
|
|
"transform-gpu"
|
|
)
|
|
|
|
/**
|
|
* Dialog provides a modal dialog, for prompting a user for input or confirmation
|
|
* before proceeding.
|
|
*/
|
|
export default function Dialog(props: Props) {
|
|
const {
|
|
open,
|
|
className,
|
|
defaultOpen,
|
|
onOpenChange,
|
|
trigger,
|
|
title,
|
|
titleSuffixDecoration,
|
|
children,
|
|
restoreFocus = true,
|
|
onPointerDownOutside,
|
|
} = props
|
|
|
|
return (
|
|
<DialogPrimitive.Root
|
|
open={open}
|
|
defaultOpen={defaultOpen}
|
|
onOpenChange={onOpenChange}
|
|
>
|
|
{trigger && (
|
|
<DialogPrimitive.Trigger asChild>{trigger}</DialogPrimitive.Trigger>
|
|
)}
|
|
<PortalContainerContext.Consumer>
|
|
{(portalContainer) => (
|
|
<DialogPrimitive.Portal container={portalContainer}>
|
|
<DialogPrimitive.Overlay className={dialogOverlay}>
|
|
<DialogPrimitive.Content
|
|
aria-label={title}
|
|
className={cx(dialogWindow, className)}
|
|
onCloseAutoFocus={
|
|
// Cancel the focus restore if `restoreFocus` is set to false
|
|
restoreFocus === false ? (e) => e.preventDefault() : undefined
|
|
}
|
|
onPointerDownOutside={onPointerDownOutside}
|
|
>
|
|
<DialogErrorBoundary>
|
|
<header className="flex items-center justify-between space-x-4 mb-5 mr-8">
|
|
<div className="font-semibold text-lg truncate">
|
|
{title}
|
|
{titleSuffixDecoration}
|
|
</div>
|
|
</header>
|
|
{children}
|
|
<DialogPrimitive.Close asChild>
|
|
<Button
|
|
variant="minimal"
|
|
className="absolute top-5 right-5 px-2 py-2"
|
|
>
|
|
<X
|
|
aria-hidden
|
|
className="h-[1.25em] w-[1.25em] stroke-current"
|
|
/>
|
|
</Button>
|
|
</DialogPrimitive.Close>
|
|
</DialogErrorBoundary>
|
|
</DialogPrimitive.Content>
|
|
</DialogPrimitive.Overlay>
|
|
</DialogPrimitive.Portal>
|
|
)}
|
|
</PortalContainerContext.Consumer>
|
|
</DialogPrimitive.Root>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Dialog.Form is a standard way of providing form-based interactions in a
|
|
* Dialog component. Prefer it to custom form implementations. See each props
|
|
* documentation for details.
|
|
*
|
|
* <Dialog.Form cancelButton submitButton="Save" onSubmit={saveThing}>
|
|
* <input type="text" value={myValue} onChange={myChangeHandler} />
|
|
* </Dialog.Form>
|
|
*/
|
|
Dialog.Form = DialogForm
|
|
|
|
type FormProps = {
|
|
/**
|
|
* destructive declares whether the submit button should be styled as a danger
|
|
* button or not. Prefer `destructive` over passing a props object to
|
|
* `submitButton`, since objects cause unnecessary re-renders unless they are
|
|
* moved outside the render function.
|
|
*/
|
|
destructive?: boolean
|
|
/**
|
|
* children is the content of the dialog form.
|
|
*/
|
|
children?: React.ReactNode
|
|
/**
|
|
* disabled determines whether the submit button should be disabled. The
|
|
* cancel button cannot be disabled via this prop.
|
|
*/
|
|
disabled?: boolean
|
|
/**
|
|
* loading determines whether the submit button should display a loading state
|
|
* and the cancel button should be disabled.
|
|
*/
|
|
loading?: boolean
|
|
/**
|
|
* cancelButton determines how the cancel button looks. You can pass `true`,
|
|
* which adds a default button, pass a string which changes the button label,
|
|
* or pass an object, which is a set of props to pass to a `Button` component.
|
|
* Any unspecified props will fall back to default values.
|
|
*
|
|
* <Dialog.Form cancelButton />
|
|
* <Dialog.Form cancelButton="Done" />
|
|
* <Dialog.Form cancelButton={{ children: "Back", variant: "primary" }} />
|
|
*/
|
|
cancelButton?: ButtonProp
|
|
/**
|
|
* submitButton determines how the submit button looks. You can pass `true`,
|
|
* which adds a default button, pass a string which changes the button label,
|
|
* or pass an object, which is a set of props to pass to a `Button` component.
|
|
* Any unspecified props will fall back to default values.
|
|
*
|
|
* <Dialog.Form submitButton />
|
|
* <Dialog.Form submitButton="Save" />
|
|
* <Dialog.Form submitButton="Delete" destructive />
|
|
* <Dialog.Form submitButton={{ children: "Banana", className: "bg-yellow-500" }} />
|
|
*/
|
|
submitButton?: ButtonProp
|
|
|
|
/**
|
|
* onSubmit is the callback to use when the form is submitted. Using `onSubmit`
|
|
* is preferrable to a `onClick` handler on `submitButton`, which doesn't get
|
|
* triggered on keyboard events.
|
|
*/
|
|
onSubmit?: () => void
|
|
|
|
/**
|
|
* autoFocus makes it easy to focus a particular action button without
|
|
* overriding the button props.
|
|
*/
|
|
autoFocus?: "submit" | "cancel"
|
|
}
|
|
|
|
function DialogForm(props: FormProps) {
|
|
const {
|
|
children,
|
|
disabled = false,
|
|
destructive = false,
|
|
loading = false,
|
|
autoFocus = "submit",
|
|
cancelButton,
|
|
submitButton,
|
|
onSubmit,
|
|
} = props
|
|
|
|
const hasFooter = Boolean(cancelButton || submitButton)
|
|
const handleSubmit = (e: FormEvent) => {
|
|
e.preventDefault()
|
|
onSubmit?.()
|
|
}
|
|
|
|
const cancelAutoFocus = Boolean(
|
|
cancelButton && !loading && autoFocus === "cancel"
|
|
)
|
|
const submitAutoFocus = Boolean(
|
|
submitButton && !loading && !disabled && autoFocus === "submit"
|
|
)
|
|
const submitIntent = destructive ? "danger" : "primary"
|
|
|
|
let cancelButtonEl = null
|
|
|
|
if (cancelButton) {
|
|
cancelButtonEl =
|
|
cancelButton === true ? (
|
|
<Button
|
|
{...cancelButtonDefaultProps}
|
|
autoFocus={cancelAutoFocus}
|
|
disabled={loading}
|
|
/>
|
|
) : typeof cancelButton === "string" ? (
|
|
<Button
|
|
{...cancelButtonDefaultProps}
|
|
autoFocus={cancelAutoFocus}
|
|
children={cancelButton}
|
|
disabled={loading}
|
|
/>
|
|
) : (
|
|
<Button
|
|
{...cancelButtonDefaultProps}
|
|
autoFocus={cancelAutoFocus}
|
|
disabled={loading}
|
|
{...cancelButton}
|
|
/>
|
|
)
|
|
|
|
const hasCustomCancelAction =
|
|
isObject(cancelButton) && cancelButton.onClick !== undefined
|
|
if (!hasCustomCancelAction) {
|
|
cancelButtonEl = (
|
|
<DialogPrimitive.Close asChild>{cancelButtonEl}</DialogPrimitive.Close>
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
{children}
|
|
{hasFooter && (
|
|
<footer className="flex mt-10 justify-end space-x-4">
|
|
{cancelButtonEl}
|
|
{submitButton && (
|
|
<>
|
|
{submitButton === true ? (
|
|
<Button
|
|
{...submitButtonDefaultProps}
|
|
intent={submitIntent}
|
|
autoFocus={submitAutoFocus}
|
|
disabled={loading || disabled}
|
|
/>
|
|
) : typeof submitButton === "string" ? (
|
|
<Button
|
|
{...submitButtonDefaultProps}
|
|
intent={submitIntent}
|
|
children={submitButton}
|
|
autoFocus={submitAutoFocus}
|
|
disabled={loading || disabled}
|
|
/>
|
|
) : (
|
|
<Button
|
|
{...submitButtonDefaultProps}
|
|
intent={submitIntent}
|
|
autoFocus={submitAutoFocus}
|
|
disabled={loading || disabled}
|
|
{...submitButton}
|
|
/>
|
|
)}
|
|
</>
|
|
)}
|
|
</footer>
|
|
)}
|
|
</form>
|
|
)
|
|
}
|
|
|
|
const cancelButtonDefaultProps: Pick<
|
|
ComponentProps<typeof Button>,
|
|
"type" | "intent" | "sizeVariant" | "children"
|
|
> = {
|
|
type: "button",
|
|
intent: "base",
|
|
sizeVariant: "medium",
|
|
children: "Cancel",
|
|
}
|
|
|
|
const submitButtonDefaultProps: Pick<
|
|
ComponentProps<typeof Button>,
|
|
"type" | "sizeVariant" | "children" | "autoFocus"
|
|
> = {
|
|
type: "submit",
|
|
sizeVariant: "medium",
|
|
children: "Submit",
|
|
}
|
|
|
|
type DialogErrorBoundaryProps = {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
class DialogErrorBoundary extends Component<
|
|
DialogErrorBoundaryProps,
|
|
{ hasError: boolean }
|
|
> {
|
|
constructor(props: DialogErrorBoundaryProps) {
|
|
super(props)
|
|
this.state = { hasError: false }
|
|
}
|
|
|
|
static getDerivedStateFromError() {
|
|
return { hasError: true }
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
console.log(error, errorInfo)
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return <div className="font-semibold text-lg">Something went wrong.</div>
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
}
|