UNPKG

@atlaskit/pragmatic-drag-and-drop-react-accessibility

Version:

An optional package for Pragmatic drag and drop containing react components to assist with setting up accessible experiences

88 lines (84 loc) • 3.2 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["children", "isSelected", "testId", "appearance", "type"]; /* eslint-disable @atlaskit/design-system/no-deprecated-imports -- Preserve existing drag handle behavior while focus-ring usage is reviewed separately. */ /** * @jsxRuntime classic * @jsx jsx */ import { forwardRef } from 'react'; // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 import { css, jsx } from '@emotion/react'; import FocusRing from '@atlaskit/focus-ring/focus-ring'; /** * Cannot use `@atlaskit/button` here because it cancels `mousedown` events * which prevents dragging. */ var buttonStyles = css({ color: "var(--ds-text, #292A2E)", borderRadius: "var(--ds-radius-small, 4px)", padding: "var(--ds-space-0, 0px)", width: 'max-content', border: 'none', cursor: 'grab', display: 'flex' }); /** * As `@atlaskit/ds-lib/is-safari`, which this public package cannot use. */ function isSafari() { var userAgent = typeof navigator === 'undefined' ? '' : navigator.userAgent.toLowerCase(); return userAgent.includes('safari') && !userAgent.includes('chrome'); } var buttonAppearanceStyles = { default: css({ backgroundColor: "var(--ds-background-neutral, #0515240F)", '&:hover': { backgroundColor: "var(--ds-background-neutral-hovered, #0B120E24)" }, '&:active': { backgroundColor: "var(--ds-background-neutral-pressed, #080F214A)" } }), subtle: css({ backgroundColor: "var(--ds-background-neutral-subtle, #00000000)", '&:hover': { backgroundColor: "var(--ds-background-neutral-subtle-hovered, #0515240F)" }, '&:active': { backgroundColor: "var(--ds-background-neutral-subtle-pressed, #0B120E24)" } }), selected: css({ backgroundColor: "var(--ds-background-selected, #E9F2FE)", color: "var(--ds-text-selected, #1868DB)" }) }; /** * A button with pre-configured styling to look like a drag handle. * * This component uses a native button because the `@atlaskit/button` * cancels `mouseDown` events, which prevents dragging. */ export var DragHandleButtonBase = /*#__PURE__*/forwardRef(function DragHandleButton(_ref, ref) { var children = _ref.children, _ref$isSelected = _ref.isSelected, isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected, testId = _ref.testId, _ref$appearance = _ref.appearance, appearanceProp = _ref$appearance === void 0 ? 'default' : _ref$appearance, _ref$type = _ref.type, type = _ref$type === void 0 ? 'button' : _ref$type, buttonProps = _objectWithoutProperties(_ref, _excluded); var appearance = isSelected ? 'selected' : appearanceProp; return jsx(FocusRing, null, jsx("button", _extends({ ref: ref, css: [buttonStyles, buttonAppearanceStyles[appearance]], "data-testid": testId, type: type // Safari does not focus a button on a click. As in `Pressable`, a `tabIndex` lets the click // focus the handle, as in Chrome. , tabIndex: isSafari() ? 0 : undefined }, buttonProps), children)); });