UNPKG

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

Version:

An optional Pragmatic drag and drop package containing react components that provide a visual indication about what the user will achieve when the drop (eg lines)

82 lines (78 loc) 3.13 kB
/* line.tsx generated by @compiled/babel-plugin v0.39.1 */ /* eslint-disable @atlaskit/ui-styling-standard/enforce-style-prop */ import "./line.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { presetStrokeColors, presetStrokeWidth } from '../presets'; const edgeToOrientationMap = { top: 'horizontal', bottom: 'horizontal', left: 'vertical', right: 'vertical' }; const baseStyles = { root: "_1e0c1ule _kqswstnw _1pbykb7n _lcxvglyw _bfhkys7w _rfx31ssb _3l8810ly _kzdanqa1 _15m6ys7w _cfu11ld9 _1kt9b3bt _1cs8stnw _13y0usvi _1mp4vjfa _kfgtvjfa" }; const orientationStyles = { horizontal: "_4t3i10ly _1e02fghn _rjxpidpf _z5wtuj5p", vertical: "_1bsb10ly _154ifghn _94n5idpf _1aukuj5p" }; const edgeStyles = { top: "_154ihv0e _1auk70hn", right: "_1xi2hv0e _ooun70hn", bottom: "_94n5hv0e _19wo70hn", left: "_1ltvhv0e _qnec70hn" }; const lineStartFrom = { // - half the terminal bleeding out the containing element // - half the terminal inside the containing element (we need to position the line next to this) terminal: ({ indent }) => `calc(var(--terminal-radius) + ${indent})`, // The full terminal is inside the containing element (we need to position the line next to this) 'terminal-no-bleed': ({ indent }) => `calc(var(--terminal-diameter) + ${indent})`, // No terminal to worry about, line should take up all the space 'no-terminal': ({ indent }) => indent }; export function Line({ edge, gap = '0px', indent = '0px', strokeColor = presetStrokeColors.default, strokeWidth = presetStrokeWidth, type = 'terminal' }) { const orientation = edgeToOrientationMap[edge]; return /*#__PURE__*/React.createElement("div", { style: { // ## All '--stroke-color': strokeColor, '--stroke-width': strokeWidth, // Shift line and terminal on the main access to account for gaps between items '--main-axis-offset': `calc(-0.5 * (${gap} + var(--stroke-width)))`, // ## Line // If there is a terminal, we want the line to start from next to it '--line-main-axis-start': lineStartFrom[type]({ indent }), // ## Terminal '--terminal-display': type === 'no-terminal' ? 'none' : 'block', '--terminal-diameter': 'calc(var(--stroke-width) * 4)', '--terminal-radius': 'calc(var(--terminal-diameter) / 2)', // The line is positioned to account for the the terminal (--line-main-axis-start). // The terminal is rendered relative to the line (it's a `::before`) // We need to pull the terminal backwards so it sits before the start of the line '--terminal-main-axis-start': 'calc(-1 * var(--terminal-diameter))', // Pull the terminal backwards on the cross axis (eg "up" on "vertical") // so the center of the terminal lines up with the center of the line '--terminal-cross-axis-offset': 'calc(calc(var(--stroke-width) - var(--terminal-diameter)) / 2)' }, className: ax([baseStyles.root, orientationStyles[orientation], edgeStyles[edge]]) }); } // For React.lazy export default Line;