@contentful/f36-drag-handle 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.mdx CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: 'DragHandle'
3
3
  type: 'component'
4
+ status: 'stable'
4
5
  slug: /components/drag-handle/
5
6
  github: 'https://github.com/contentful/forma-36/tree/main/packages/components/drag-handle'
6
7
  typescript: ./src/DragHandle.tsx
@@ -8,7 +9,7 @@ storybook: 'https://f36-storybook.contentful.com/?path=/story/components-draghan
8
9
  ---
9
10
 
10
11
  import { Heading, Stack, TextLink } from '@contentful/f36-components';
11
- import { ExternalLinkIcon } from '@contentful/f36-icons';
12
+ import { ArrowSquareOutIcon } from '@contentful/f36-icons';
12
13
 
13
14
  DragHandle is a new component to make it easier when creating draggable elements. it contains the styling for focus, hover and dragging states.
14
15
  This component only needs to be used if you're creating a custom component with drag, some of our components already have this implemented, for example [Card](/components/card).
@@ -25,28 +26,21 @@ import { DragHandle } from '@contentful/f36-drag-handle';
25
26
 
26
27
  The DragHandle can be styled based on the props you pass to it:
27
28
 
28
- **Base**:
29
+ ### Variants
29
30
 
30
- ```jsx
31
- <DragHandle label="Drag handle" />
32
- ```
31
+ DragHandle has 2 different variants:
33
32
 
34
- **Active**:
35
-
36
- ```jsx
37
- <DragHandle isActive label="Active drag handle" />
38
- ```
33
+ - **Secondary** - Default variant.
34
+ - **Transparent** - For having an unstyled DragHandle.
39
35
 
40
- **Focused**:
36
+ ```jsx file=./examples/DragHandleVariantsExample.tsx
41
37
 
42
- ```jsx
43
- <DragHandle isFocused label="Focus drag handle" />
44
38
  ```
45
39
 
46
- **Hovered**:
40
+ ### States
41
+
42
+ ```jsx file=./examples/DragHandleStatesExample.tsx
47
43
 
48
- ```jsx
49
- <DragHandle isHovered label="Hovered drag handle" />
50
44
  ```
51
45
 
52
46
  ### Card example
@@ -74,7 +68,7 @@ The DragHandle can be styled based on the props you pass to it:
74
68
  href="https://f36-storybook.contentful.com/?path=/story/components-draghandle"
75
69
  target="_blank"
76
70
  alignIcon="end"
77
- icon={<ExternalLinkIcon />}
71
+ icon={<ArrowSquareOutIcon />}
78
72
  >
79
73
  Open in Storybook
80
74
  </TextLink>
package/dist/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
- import a, { useState, useCallback } from 'react';
1
+ import s, { useState, useCallback } from 'react';
2
2
  import { cx, css } from 'emotion';
3
- import { DragIcon } from '@contentful/f36-icons';
4
3
  import t from '@contentful/f36-tokens';
4
+ import { DotsSixVerticalIcon } from '@contentful/f36-icons';
5
+ import { hexToRGBA } from '@contentful/f36-utils';
5
6
 
6
- var $=Object.defineProperty,j=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var x=(o,r,e)=>r in o?$(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e,i=(o,r)=>{for(var e in r||(r={}))P.call(r,e)&&x(o,e,r[e]);if(l)for(var e of l(r))h.call(r,e)&&x(o,e,r[e]);return o},b=(o,r)=>j(o,z(r));var A=(o,r)=>{var e={};for(var n in o)P.call(o,n)&&r.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&l)for(var n of l(o))r.indexOf(n)<0&&h.call(o,n)&&(e[n]=o[n]);return e};var L=()=>({label:css({position:"absolute",width:"1px",height:"1px",padding:0,margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",border:0}),root:({isActive:o,isFocused:r,isHovered:e})=>cx(css({alignItems:"center",backgroundColor:t.gray100,border:0,borderBottomLeftRadius:t.borderRadiusMedium,borderRight:`1px solid ${t.gray200}`,borderTopLeftRadius:t.borderRadiusMedium,boxSizing:"border-box",display:"flex",justifyContent:"center",padding:0,position:"relative",transition:`background-color ${t.transitionDurationDefault} ${t.transitionEasingDefault}`,width:t.spacingL,"&:hover":{backgroundColor:t.gray200},"&:focus":{boxShadow:t.glowPrimary},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:t.glowPrimary}}),(o||r||e)&&css({backgroundColor:t.gray200,cursor:o?"grabbing":"grab"}))});var K="div";function O(o,r){let e=L(),D=o,{as:n=K,className:M,isActive:_,isFocused:w,isHovered:C,label:g,onBlur:p,onFocus:u,onMouseEnter:c,onMouseLeave:m,testId:G="cf-ui-drag-handle",style:N}=D,y=A(D,["as","className","isActive","isFocused","isHovered","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style"]),[I,E]=useState(w),[R,H]=useState(C),S=useCallback(s=>{E(!0),u&&u(s);},[u]),k=useCallback(s=>{E(!1),p&&p(s);},[p]),B=useCallback(s=>{H(!0),c&&c(s);},[c]),U=useCallback(s=>{H(!1),m&&m(s);},[m]),v={className:cx(e.root({isActive:_,isFocused:I,isHovered:R}),M),"data-test-id":G,onBlur:k,onFocus:S,onMouseEnter:B,onMouseLeave:U,ref:r,style:N};return n==="div"?a.createElement("div",b(i(i({},y),v),{role:"button",tabIndex:0}),a.createElement(DragIcon,{variant:"muted"}),a.createElement("span",{className:e.label},g)):a.createElement("button",b(i(i({},y),v),{type:"button"}),a.createElement(DragIcon,{variant:"muted"}),a.createElement("span",{className:e.label},g))}var Q=a.forwardRef(O);
7
+ var V=Object.defineProperty,q=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var x=(o,r,e)=>r in o?V(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e,l=(o,r)=>{for(var e in r||(r={}))P.call(r,e)&&x(o,e,r[e]);if(d)for(var e of d(r))h.call(r,e)&&x(o,e,r[e]);return o},g=(o,r)=>q(o,J(r));var A=(o,r)=>{var e={};for(var n in o)P.call(o,n)&&r.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&d)for(var n of d(o))r.indexOf(n)<0&&h.call(o,n)&&(e[n]=o[n]);return e};var T=()=>({label:css({position:"absolute",width:"1px",height:"1px",padding:0,margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",border:0}),root:({isActive:o,isFocused:r,isHovered:e,variant:n})=>cx(css({alignItems:"center",backgroundColor:"transparent",border:0,boxSizing:"border-box",display:"flex",justifyContent:"center",padding:0,margin:0,position:"relative",transition:`background-color ${t.transitionDurationDefault} ${t.transitionEasingDefault}`,width:t.spacingL,"&:focus":{boxShadow:t.glowPrimary},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:t.glowPrimary}}),n==="secondary"&&css({borderRight:`1px solid ${t.gray200}`,borderTopLeftRadius:t.borderRadiusMedium,borderBottomLeftRadius:t.borderRadiusMedium,backgroundColor:t.gray100,"&:hover":{backgroundColor:hexToRGBA(t.gray900,.08)}}),n==="secondary"&&(o||r||e)&&css({backgroundColor:hexToRGBA(t.gray900,.08)}),(o||r||e)&&css({cursor:o?"grabbing":"grab"}))});var Q="div";function W(o,r){let e=T(),D=o,{as:n=Q,className:C,isActive:w,isFocused:G,isHovered:k,label:f,onBlur:c,onFocus:u,onMouseEnter:m,onMouseLeave:b,testId:N="cf-ui-drag-handle",style:R,variant:S="secondary"}=D,y=A(D,["as","className","isActive","isFocused","isHovered","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","variant"]),[I,E]=useState(G),[B,H]=useState(k),U=useCallback(a=>{E(!0),u&&u(a);},[u]),$=useCallback(a=>{E(!1),c&&c(a);},[c]),j=useCallback(a=>{H(!0),m&&m(a);},[m]),z=useCallback(a=>{H(!1),b&&b(a);},[b]),v={className:cx(e.root({isActive:w,isFocused:I,isHovered:B,variant:S}),C),"data-test-id":N,onBlur:$,onFocus:U,onMouseEnter:j,onMouseLeave:z,ref:r,style:R};return n==="div"?s.createElement("div",g(l(l({},y),v),{role:"button",tabIndex:0}),s.createElement(DotsSixVerticalIcon,{color:t.gray600}),s.createElement("span",{className:e.label},f)):s.createElement("button",g(l(l({},y),v),{type:"button"}),s.createElement(DotsSixVerticalIcon,{color:t.gray600}),s.createElement("span",{className:e.label},f))}var X=s.forwardRef(W);
7
8
 
8
- export { Q as DragHandle };
9
+ export { X as DragHandle };
10
+ //# sourceMappingURL=out.js.map
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DragHandle.tsx","../../src/DragHandle.styles.ts"],"names":["React","useCallback","useState","cx","DragIcon","css","tokens","getStyles","isActive","isFocused","isHovered","DRAG_HANDLE_DEFAULT_TAG","_DragHandle","props","ref","styles","_a","as","className","isFocusedProp","isHoveredProp","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","otherProps","__objRest","setisFocused","setisHovered","handleFocus","event","handleBlur","handleMouseEnter","handleMouseLeave","commonProps","__spreadProps","__spreadValues","DragHandle"],"mappings":"+kBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAKK,QACP,OAAS,MAAAC,MAAU,UAOnB,OAAS,YAAAC,MAAgB,wBCfzB,OAAS,MAAAD,EAAI,OAAAE,MAAW,UACxB,OAAOC,MAAY,yBAEZ,IAAMC,EAAY,KAAO,CAC9B,MAAOF,EAAI,CACT,SAAU,WACV,MAAO,MACP,OAAQ,MACR,QAAS,EACT,OAAQ,OACR,SAAU,SACV,KAAM,mBACN,OAAQ,CACV,CAAC,EACD,KAAM,CAAC,CACL,SAAAG,EACA,UAAAC,EACA,UAAAC,CACF,IAKSP,EACLE,EAAI,CACF,WAAY,SACZ,gBAAiBC,EAAO,QACxB,OAAQ,EACR,uBAAwBA,EAAO,mBAC/B,YAAa,aAAaA,EAAO,UACjC,oBAAqBA,EAAO,mBAC5B,UAAW,aACX,QAAS,OACT,eAAgB,SAChB,QAAS,EACT,SAAU,WACV,WAAY,oBAAoBA,EAAO,6BAA6BA,EAAO,0BAC3E,MAAOA,EAAO,SACd,UAAW,CACT,gBAAiBA,EAAO,OAC1B,EACA,UAAW,CACT,UAAWA,E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cC,EACd,IAAAtB,EACA,MAAAa,CACF,EAEA,OAAIV,IAAO,MAEPjB,EAAA,cAAC,MAAAsC,EAAAC,IAAA,GAAQX,GAAgBS,GAAxB,CAAqC,KAAK,SAAS,SAAU,IAC5DrC,EAAA,cAACI,EAAA,CAAS,QAAQ,QAAQ,EAC1BJ,EAAA,cAAC,QAAK,UAAWe,EAAO,OAAQM,CAAM,CACxC,EAKFrB,EAAA,cAAC,SAAAsC,EAAAC,IAAA,GAAWX,GAAgBS,GAA3B,CAAwC,KAAK,WAC5CrC,EAAA,cAACI,EAAA,CAAS,QAAQ,QAAQ,EAC1BJ,EAAA,cAAC,QAAK,UAAWe,EAAO,OAAQM,CAAM,CACxC,CAEJ,CAEO,IAAMmB,EAITxC,EAAM,WAAWY,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type ElementType,\n type FocusEventHandler,\n type MouseEventHandler,\n type Ref,\n} from 'react';\nimport { cx } from 'emotion';\nimport type {\n PolymorphicComponent,\n PolymorphicProps,\n CommonProps,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { DragIcon } from '@contentful/f36-icons';\n\nimport { getStyles } from './DragHandle.styles';\n\n// We use div instead of a button because react-sortable-hoc lib cancels sorting if the event target is button.\n//\n// The other alternative way to fix it was to pass a custom `shouldCancelStart` callback,\n// in every place where we use this component with react-sortable-hoc.\n// (the custom callback with all the logic from default callback, but without button event cancelation).\n// So we decided that just changing it to the div, as it was in v3, is a better fix.\n//\n// default shouldCancelStart callback:\n// https://github.com/clauderic/react-sortable-hoc/blob/d94ba3cc67cfc7d6d460b585e7723bdb50015e53/src/SortableContainer/defaultShouldCancelStart.js\nconst DRAG_HANDLE_DEFAULT_TAG = 'div';\n\nexport interface DragHandleInternalProps extends CommonProps {\n /**\n * The element used for the root node\n * @default div\n */\n as?: 'button' | 'div';\n /**\n * Applies styling for when the component is actively being dragged by\n * the user\n */\n isActive?: boolean;\n /**\n * Applies focus styling\n */\n isFocused?: boolean;\n /**\n * Applies hover styling\n */\n isHovered?: boolean;\n /**\n * Label rendered in DragHandle - not visible on screen as its purpose\n * is for screen readers only\n */\n label: string;\n /**\n * Set type button for div element\n */\n type?: string;\n}\n\nexport type DragHandleProps<\n E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG,\n> = PolymorphicProps<DragHandleInternalProps, E>;\n\nfunction _DragHandle<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG>(\n props: DragHandleProps<E>,\n ref: Ref<any>,\n) {\n const styles = getStyles();\n const {\n as = DRAG_HANDLE_DEFAULT_TAG,\n className,\n isActive,\n isFocused: isFocusedProp,\n isHovered: isHoveredProp,\n label,\n onBlur,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n testId = 'cf-ui-drag-handle',\n style,\n ...otherProps\n } = props;\n const [isFocused, setisFocused] = useState(isFocusedProp);\n const [isHovered, setisHovered] = useState(isHoveredProp);\n\n const handleFocus = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(true);\n\n if (onFocus) {\n onFocus(event);\n }\n },\n [onFocus],\n );\n\n const handleBlur = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(false);\n\n if (onBlur) {\n onBlur(event);\n }\n },\n [onBlur],\n );\n\n const handleMouseEnter = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(true);\n\n if (onMouseEnter) {\n onMouseEnter(event);\n }\n },\n [onMouseEnter],\n );\n\n const handleMouseLeave = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(false);\n\n if (onMouseLeave) {\n onMouseLeave(event);\n }\n },\n [onMouseLeave],\n );\n\n const commonProps = {\n className: cx(styles.root({ isActive, isFocused, isHovered }), className),\n 'data-test-id': testId,\n onBlur: handleBlur,\n onFocus: handleFocus,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n ref,\n style,\n };\n\n if (as === 'div') {\n return (\n <div {...otherProps} {...commonProps} role=\"button\" tabIndex={0}>\n <DragIcon variant=\"muted\" />\n <span className={styles.label}>{label}</span>\n </div>\n );\n }\n\n return (\n <button {...otherProps} {...commonProps} type=\"button\">\n <DragIcon variant=\"muted\" />\n <span className={styles.label}>{label}</span>\n </button>\n );\n}\n\nexport const DragHandle: PolymorphicComponent<\n ExpandProps<DragHandleInternalProps>,\n typeof DRAG_HANDLE_DEFAULT_TAG,\n 'disabled'\n> = React.forwardRef(_DragHandle);\n","import { cx, css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = () => ({\n label: css({\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: 0,\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n border: 0,\n }),\n root: ({\n isActive,\n isFocused,\n isHovered,\n }: {\n isActive: boolean;\n isFocused: boolean;\n isHovered: boolean;\n }) => {\n return cx(\n css({\n alignItems: 'center',\n backgroundColor: tokens.gray100,\n border: 0,\n borderBottomLeftRadius: tokens.borderRadiusMedium,\n borderRight: `1px solid ${tokens.gray200}`,\n borderTopLeftRadius: tokens.borderRadiusMedium,\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n padding: 0,\n position: 'relative',\n transition: `background-color ${tokens.transitionDurationDefault} ${tokens.transitionEasingDefault}`,\n width: tokens.spacingL,\n '&:hover': {\n backgroundColor: tokens.gray200,\n },\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowPrimary,\n },\n }),\n (isActive || isFocused || isHovered) &&\n css({\n backgroundColor: tokens.gray200,\n cursor: isActive ? 'grabbing' : 'grab',\n }),\n );\n },\n});\n"]}
1
+ {"version":3,"sources":["../../src/DragHandle.tsx","../../src/DragHandle.styles.ts"],"names":["React","useCallback","useState","cx","tokens","DotsSixVerticalIcon","css","hexToRGBA","getStyles","isActive","isFocused","isHovered","variant","DRAG_HANDLE_DEFAULT_TAG","_DragHandle","props","ref","styles","_a","as","className","isFocusedProp","isHoveredProp","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","otherProps","__objRest","setisFocused","setisHovered","handleFocus","event","handleBlur","handleMouseEnter","handleMouseLeave","commonProps","__spreadProps","__spreadValues","DragHandle"],"mappings":"+kBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAKK,QACP,OAAS,MAAAC,MAAU,UACnB,OAAOC,MAAY,yBAOnB,OAAS,uBAAAC,MAA2B,wBChBpC,OAAS,MAAAF,EAAI,OAAAG,MAAW,UACxB,OAAOF,MAAY,yBACnB,OAAS,aAAAG,MAAiB,wBAGnB,IAAMC,EAAY,KAAO,CAC9B,MAAOF,EAAI,CACT,SAAU,WACV,MAAO,MACP,OAAQ,MACR,QAAS,EACT,OAAQ,OACR,SAAU,SACV,KAAM,mBACN,OAAQ,CACV,CAAC,EACD,KAAM,CAAC,CACL,SAAAG,EACA,UAAAC,EACA,UAAAC,EACA,QAAAC,CACF,IAMST,EACLG,EAAI,CACF,WAAY,SACZ,gBAAiB,cACjB,OAAQ,EACR,UAAW,aACX,QAAS,OACT,eAAgB,SAChB,QAAS,EACT,OAAQ,EACR,SAAU,WACV,WAAY,oBAAoBF,EAAO,yBAAyB,IAAIA,EAAO,uBAAuB,GAClG,MAAOA,EAAO,SACd,UAAW,CACT,UAAWA,EAAO,WACpB,EACA,8BAA+B,CAC7B,UAAW,OACb,EACA,kBAAmB,CACjB,UAAWA,EAAO,WACpB,CACF,CAAC,EACDQ,IAAY,aACVN,EAAI,CACF,YAAa,aAAaF,EAAO,OAAO,GACxC,oBAAqBA,EAAO,mBAC5B,uBAAwBA,EAAO,mBAC/B,gBAAiBA,EAAO,QACxB,UAAW,CACT,gBAAiBG,EAAUH,EAAO,QAAS,GAAI,CACjD,CACF,CAAC,EACHQ,IAAY,cACTH,GAAYC,GAAaC,IAC1BL,EAAI,CACF,gBAAiBC,EAAUH,EAAO,QAAS,GAAI,CACjD,CAAC,GACFK,GAAYC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,IAAA,GAAQX,GAAgBS,GAAxB,CAAqC,KAAK,SAAS,SAAU,IAC5DvC,EAAA,cAACK,EAAA,CAAoB,MAAOD,EAAO,QAAS,EAC5CJ,EAAA,cAAC,QAAK,UAAWiB,EAAO,OAAQM,CAAM,CACxC,EAKFvB,EAAA,cAAC,SAAAwC,EAAAC,IAAA,GAAWX,GAAgBS,GAA3B,CAAwC,KAAK,WAC5CvC,EAAA,cAACK,EAAA,CAAoB,MAAOD,EAAO,QAAS,EAC5CJ,EAAA,cAAC,QAAK,UAAWiB,EAAO,OAAQM,CAAM,CACxC,CAEJ,CAEO,IAAMmB,EAIT1C,EAAM,WAAWc,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type ElementType,\n type FocusEventHandler,\n type MouseEventHandler,\n type Ref,\n} from 'react';\nimport { cx } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport type {\n PolymorphicComponent,\n PolymorphicProps,\n CommonProps,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { DotsSixVerticalIcon } from '@contentful/f36-icons';\n\nimport { getStyles } from './DragHandle.styles';\n\n// We use div instead of a button because react-sortable-hoc lib cancels sorting if the event target is button.\n//\n// The other alternative way to fix it was to pass a custom `shouldCancelStart` callback,\n// in every place where we use this component with react-sortable-hoc.\n// (the custom callback with all the logic from default callback, but without button event cancelation).\n// So we decided that just changing it to the div, as it was in v3, is a better fix.\n//\n// default shouldCancelStart callback:\n// https://github.com/clauderic/react-sortable-hoc/blob/d94ba3cc67cfc7d6d460b585e7723bdb50015e53/src/SortableContainer/defaultShouldCancelStart.js\nconst DRAG_HANDLE_DEFAULT_TAG = 'div';\n\nexport interface DragHandleInternalProps extends CommonProps {\n /**\n * The element used for the root node\n * @default div\n */\n as?: 'button' | 'div';\n /**\n * Applies styling for when the component is actively being dragged by\n * the user\n */\n isActive?: boolean;\n /**\n * Applies focus styling\n */\n isFocused?: boolean;\n /**\n * Applies hover styling\n */\n isHovered?: boolean;\n /**\n * Label rendered in DragHandle - not visible on screen as its purpose\n * is for screen readers only\n */\n label: string;\n /**\n * Set type button for div element\n */\n type?: string;\n\n /**\n * Determines style variation\n * @default secondary\n */\n variant?: 'secondary' | 'transparent';\n}\n\nexport type DragHandleProps<\n E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG,\n> = PolymorphicProps<DragHandleInternalProps, E>;\n\nfunction _DragHandle<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG>(\n props: DragHandleProps<E>,\n ref: Ref<any>,\n) {\n const styles = getStyles();\n const {\n as = DRAG_HANDLE_DEFAULT_TAG,\n className,\n isActive,\n isFocused: isFocusedProp,\n isHovered: isHoveredProp,\n label,\n onBlur,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n testId = 'cf-ui-drag-handle',\n style,\n variant = 'secondary',\n ...otherProps\n } = props;\n const [isFocused, setisFocused] = useState(isFocusedProp);\n const [isHovered, setisHovered] = useState(isHoveredProp);\n\n const handleFocus = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(true);\n\n if (onFocus) {\n onFocus(event);\n }\n },\n [onFocus],\n );\n\n const handleBlur = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(false);\n\n if (onBlur) {\n onBlur(event);\n }\n },\n [onBlur],\n );\n\n const handleMouseEnter = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(true);\n\n if (onMouseEnter) {\n onMouseEnter(event);\n }\n },\n [onMouseEnter],\n );\n\n const handleMouseLeave = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(false);\n\n if (onMouseLeave) {\n onMouseLeave(event);\n }\n },\n [onMouseLeave],\n );\n\n const commonProps = {\n className: cx(\n styles.root({ isActive, isFocused, isHovered, variant }),\n className,\n ),\n 'data-test-id': testId,\n onBlur: handleBlur,\n onFocus: handleFocus,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n ref,\n style,\n };\n\n if (as === 'div') {\n return (\n <div {...otherProps} {...commonProps} role=\"button\" tabIndex={0}>\n <DotsSixVerticalIcon color={tokens.gray600} />\n <span className={styles.label}>{label}</span>\n </div>\n );\n }\n\n return (\n <button {...otherProps} {...commonProps} type=\"button\">\n <DotsSixVerticalIcon color={tokens.gray600} />\n <span className={styles.label}>{label}</span>\n </button>\n );\n}\n\nexport const DragHandle: PolymorphicComponent<\n ExpandProps<DragHandleInternalProps>,\n typeof DRAG_HANDLE_DEFAULT_TAG,\n 'disabled'\n> = React.forwardRef(_DragHandle);\n","import { cx, css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { hexToRGBA } from '@contentful/f36-utils';\nimport { DragHandleProps } from './DragHandle';\n\nexport const getStyles = () => ({\n label: css({\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: 0,\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n border: 0,\n }),\n root: ({\n isActive,\n isFocused,\n isHovered,\n variant,\n }: {\n isActive: boolean;\n isFocused: boolean;\n isHovered: boolean;\n variant: DragHandleProps['variant'];\n }) => {\n return cx(\n css({\n alignItems: 'center',\n backgroundColor: 'transparent',\n border: 0,\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n padding: 0,\n margin: 0, // remove the default button margin in Safari.\n position: 'relative',\n transition: `background-color ${tokens.transitionDurationDefault} ${tokens.transitionEasingDefault}`,\n width: tokens.spacingL,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowPrimary,\n },\n }),\n variant === 'secondary' &&\n css({\n borderRight: `1px solid ${tokens.gray200}`,\n borderTopLeftRadius: tokens.borderRadiusMedium,\n borderBottomLeftRadius: tokens.borderRadiusMedium,\n backgroundColor: tokens.gray100,\n '&:hover': {\n backgroundColor: hexToRGBA(tokens.gray900, 0.08),\n },\n }),\n variant === 'secondary' &&\n (isActive || isFocused || isHovered) &&\n css({\n backgroundColor: hexToRGBA(tokens.gray900, 0.08),\n }),\n (isActive || isFocused || isHovered) &&\n css({\n cursor: isActive ? 'grabbing' : 'grab',\n }),\n );\n },\n});\n"]}
@@ -0,0 +1,42 @@
1
+ import { ElementType } from 'react';
2
+ import { PolymorphicProps, PolymorphicComponent, ExpandProps, CommonProps } from '@contentful/f36-core';
3
+
4
+ declare const DRAG_HANDLE_DEFAULT_TAG = "div";
5
+ interface DragHandleInternalProps extends CommonProps {
6
+ /**
7
+ * The element used for the root node
8
+ * @default div
9
+ */
10
+ as?: 'button' | 'div';
11
+ /**
12
+ * Applies styling for when the component is actively being dragged by
13
+ * the user
14
+ */
15
+ isActive?: boolean;
16
+ /**
17
+ * Applies focus styling
18
+ */
19
+ isFocused?: boolean;
20
+ /**
21
+ * Applies hover styling
22
+ */
23
+ isHovered?: boolean;
24
+ /**
25
+ * Label rendered in DragHandle - not visible on screen as its purpose
26
+ * is for screen readers only
27
+ */
28
+ label: string;
29
+ /**
30
+ * Set type button for div element
31
+ */
32
+ type?: string;
33
+ /**
34
+ * Determines style variation
35
+ * @default secondary
36
+ */
37
+ variant?: 'secondary' | 'transparent';
38
+ }
39
+ declare type DragHandleProps<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG> = PolymorphicProps<DragHandleInternalProps, E>;
40
+ declare const DragHandle: PolymorphicComponent<ExpandProps<DragHandleInternalProps>, typeof DRAG_HANDLE_DEFAULT_TAG, 'disabled'>;
41
+
42
+ export { DragHandle, DragHandleProps };
package/dist/index.d.ts CHANGED
@@ -30,6 +30,11 @@ interface DragHandleInternalProps extends CommonProps {
30
30
  * Set type button for div element
31
31
  */
32
32
  type?: string;
33
+ /**
34
+ * Determines style variation
35
+ * @default secondary
36
+ */
37
+ variant?: 'secondary' | 'transparent';
33
38
  }
34
39
  declare type DragHandleProps<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG> = PolymorphicProps<DragHandleInternalProps, E>;
35
40
  declare const DragHandle: PolymorphicComponent<ExpandProps<DragHandleInternalProps>, typeof DRAG_HANDLE_DEFAULT_TAG, 'disabled'>;
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var a = require('react');
3
+ var s = require('react');
6
4
  var emotion = require('emotion');
7
- var f36Icons = require('@contentful/f36-icons');
8
5
  var t = require('@contentful/f36-tokens');
6
+ var f36Icons = require('@contentful/f36-icons');
7
+ var f36Utils = require('@contentful/f36-utils');
9
8
 
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
10
 
12
- var a__default = /*#__PURE__*/_interopDefaultLegacy(a);
13
- var t__default = /*#__PURE__*/_interopDefaultLegacy(t);
11
+ var s__default = /*#__PURE__*/_interopDefault(s);
12
+ var t__default = /*#__PURE__*/_interopDefault(t);
14
13
 
15
- var $=Object.defineProperty,j=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var x=(o,r,e)=>r in o?$(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e,i=(o,r)=>{for(var e in r||(r={}))P.call(r,e)&&x(o,e,r[e]);if(l)for(var e of l(r))h.call(r,e)&&x(o,e,r[e]);return o},b=(o,r)=>j(o,z(r));var A=(o,r)=>{var e={};for(var n in o)P.call(o,n)&&r.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&l)for(var n of l(o))r.indexOf(n)<0&&h.call(o,n)&&(e[n]=o[n]);return e};var L=()=>({label:emotion.css({position:"absolute",width:"1px",height:"1px",padding:0,margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",border:0}),root:({isActive:o,isFocused:r,isHovered:e})=>emotion.cx(emotion.css({alignItems:"center",backgroundColor:t__default["default"].gray100,border:0,borderBottomLeftRadius:t__default["default"].borderRadiusMedium,borderRight:`1px solid ${t__default["default"].gray200}`,borderTopLeftRadius:t__default["default"].borderRadiusMedium,boxSizing:"border-box",display:"flex",justifyContent:"center",padding:0,position:"relative",transition:`background-color ${t__default["default"].transitionDurationDefault} ${t__default["default"].transitionEasingDefault}`,width:t__default["default"].spacingL,"&:hover":{backgroundColor:t__default["default"].gray200},"&:focus":{boxShadow:t__default["default"].glowPrimary},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:t__default["default"].glowPrimary}}),(o||r||e)&&emotion.css({backgroundColor:t__default["default"].gray200,cursor:o?"grabbing":"grab"}))});var K="div";function O(o,r){let e=L(),D=o,{as:n=K,className:M,isActive:_,isFocused:w,isHovered:C,label:g,onBlur:p,onFocus:u,onMouseEnter:c,onMouseLeave:m,testId:G="cf-ui-drag-handle",style:N}=D,y=A(D,["as","className","isActive","isFocused","isHovered","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style"]),[I,E]=a.useState(w),[R,H]=a.useState(C),S=a.useCallback(s=>{E(!0),u&&u(s);},[u]),k=a.useCallback(s=>{E(!1),p&&p(s);},[p]),B=a.useCallback(s=>{H(!0),c&&c(s);},[c]),U=a.useCallback(s=>{H(!1),m&&m(s);},[m]),v={className:emotion.cx(e.root({isActive:_,isFocused:I,isHovered:R}),M),"data-test-id":G,onBlur:k,onFocus:S,onMouseEnter:B,onMouseLeave:U,ref:r,style:N};return n==="div"?a__default["default"].createElement("div",b(i(i({},y),v),{role:"button",tabIndex:0}),a__default["default"].createElement(f36Icons.DragIcon,{variant:"muted"}),a__default["default"].createElement("span",{className:e.label},g)):a__default["default"].createElement("button",b(i(i({},y),v),{type:"button"}),a__default["default"].createElement(f36Icons.DragIcon,{variant:"muted"}),a__default["default"].createElement("span",{className:e.label},g))}var Q=a__default["default"].forwardRef(O);
14
+ var V=Object.defineProperty,q=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var x=(o,r,e)=>r in o?V(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e,l=(o,r)=>{for(var e in r||(r={}))P.call(r,e)&&x(o,e,r[e]);if(d)for(var e of d(r))h.call(r,e)&&x(o,e,r[e]);return o},g=(o,r)=>q(o,J(r));var A=(o,r)=>{var e={};for(var n in o)P.call(o,n)&&r.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&d)for(var n of d(o))r.indexOf(n)<0&&h.call(o,n)&&(e[n]=o[n]);return e};var T=()=>({label:emotion.css({position:"absolute",width:"1px",height:"1px",padding:0,margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",border:0}),root:({isActive:o,isFocused:r,isHovered:e,variant:n})=>emotion.cx(emotion.css({alignItems:"center",backgroundColor:"transparent",border:0,boxSizing:"border-box",display:"flex",justifyContent:"center",padding:0,margin:0,position:"relative",transition:`background-color ${t__default.default.transitionDurationDefault} ${t__default.default.transitionEasingDefault}`,width:t__default.default.spacingL,"&:focus":{boxShadow:t__default.default.glowPrimary},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:t__default.default.glowPrimary}}),n==="secondary"&&emotion.css({borderRight:`1px solid ${t__default.default.gray200}`,borderTopLeftRadius:t__default.default.borderRadiusMedium,borderBottomLeftRadius:t__default.default.borderRadiusMedium,backgroundColor:t__default.default.gray100,"&:hover":{backgroundColor:f36Utils.hexToRGBA(t__default.default.gray900,.08)}}),n==="secondary"&&(o||r||e)&&emotion.css({backgroundColor:f36Utils.hexToRGBA(t__default.default.gray900,.08)}),(o||r||e)&&emotion.css({cursor:o?"grabbing":"grab"}))});var Q="div";function W(o,r){let e=T(),D=o,{as:n=Q,className:C,isActive:w,isFocused:G,isHovered:k,label:f,onBlur:c,onFocus:u,onMouseEnter:m,onMouseLeave:b,testId:N="cf-ui-drag-handle",style:R,variant:S="secondary"}=D,y=A(D,["as","className","isActive","isFocused","isHovered","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","variant"]),[I,E]=s.useState(G),[B,H]=s.useState(k),U=s.useCallback(a=>{E(!0),u&&u(a);},[u]),$=s.useCallback(a=>{E(!1),c&&c(a);},[c]),j=s.useCallback(a=>{H(!0),m&&m(a);},[m]),z=s.useCallback(a=>{H(!1),b&&b(a);},[b]),v={className:emotion.cx(e.root({isActive:w,isFocused:I,isHovered:B,variant:S}),C),"data-test-id":N,onBlur:$,onFocus:U,onMouseEnter:j,onMouseLeave:z,ref:r,style:R};return n==="div"?s__default.default.createElement("div",g(l(l({},y),v),{role:"button",tabIndex:0}),s__default.default.createElement(f36Icons.DotsSixVerticalIcon,{color:t__default.default.gray600}),s__default.default.createElement("span",{className:e.label},f)):s__default.default.createElement("button",g(l(l({},y),v),{type:"button"}),s__default.default.createElement(f36Icons.DotsSixVerticalIcon,{color:t__default.default.gray600}),s__default.default.createElement("span",{className:e.label},f))}var X=s__default.default.forwardRef(W);
16
15
 
17
- exports.DragHandle = Q;
16
+ exports.DragHandle = X;
17
+ //# sourceMappingURL=out.js.map
18
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/DragHandle.tsx","../src/DragHandle.styles.ts"],"names":["React","useCallback","useState","cx","DragIcon","css","tokens","getStyles","isActive","isFocused","isHovered","DRAG_HANDLE_DEFAULT_TAG","_DragHandle","props","ref","styles","_a","as","className","isFocusedProp","isHoveredProp","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","otherProps","__objRest","setisFocused","setisHovered","handleFocus","event","handleBlur","handleMouseEnter","handleMouseLeave","commonProps","__spreadProps","__spreadValues","DragHandle"],"mappings":"+kBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAKK,QACP,OAAS,MAAAC,MAAU,UAOnB,OAAS,YAAAC,MAAgB,wBCfzB,OAAS,MAAAD,EAAI,OAAAE,MAAW,UACxB,OAAOC,MA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FA,EAAQU,CAAK,CAEjB,EACA,CAACV,CAAO,CACV,EAEMW,EAAajC,EAChBgC,GAAU,CACTH,EAAa,EAAK,EAEdR,GACFA,EAAOW,CAAK,CAEhB,EACA,CAACX,CAAM,CACT,EAEMa,EAAmBlC,EACtBgC,GAAU,CACTF,EAAa,EAAI,EAEbP,GACFA,EAAaS,CAAK,CAEtB,EACA,CAACT,CAAY,CACf,EAEMY,EAAmBnC,EACtBgC,GAAU,CACTF,EAAa,EAAK,EAEdN,GACFA,EAAaQ,CAAK,CAEtB,EACA,CAACR,CAAY,CACf,EAEMY,EAAc,CAClB,UAAWlC,EAAGY,EAAO,KAAK,CAAE,SAAAP,EAAU,UAAAC,EAAW,UAAAC,CAAU,CAAC,EAAGQ,CAAS,EACxE,eAAgBQ,EAChB,OAAQQ,EACR,QAASF,EACT,aAAcG,EACd,aAAcC,EACd,IAAAtB,EACA,MAAAa,CACF,EAEA,OAAIV,IAAO,MAEPjB,EAAA,cAAC,MAAAsC,EAAAC,IAAA,GAAQX,GAAgBS,GAAxB,CAAqC,KAAK,SAAS,SAAU,IAC5DrC,EAAA,cAACI,EAAA,CAAS,QAAQ,QAAQ,EAC1BJ,EAAA,cAAC,QAAK,UAAWe,EAAO,OAAQM,CAAM,CACxC,EAKFrB,EAAA,cAAC,SAAAsC,EAAAC,IAAA,GAAWX,GAAgBS,GAA3B,CAAwC,KAAK,WAC5CrC,EAAA,cAACI,EAAA,CAAS,QAAQ,QAAQ,EAC1BJ,EAAA,cAAC,QAAK,UAAWe,EAAO,OAAQM,CAAM,CACxC,CAEJ,CAEO,IAAMmB,EAITxC,EAAM,WAAWY,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type ElementType,\n type FocusEventHandler,\n type MouseEventHandler,\n type Ref,\n} from 'react';\nimport { cx } from 'emotion';\nimport type {\n PolymorphicComponent,\n PolymorphicProps,\n CommonProps,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { DragIcon } from '@contentful/f36-icons';\n\nimport { getStyles } from './DragHandle.styles';\n\n// We use div instead of a button because react-sortable-hoc lib cancels sorting if the event target is button.\n//\n// The other alternative way to fix it was to pass a custom `shouldCancelStart` callback,\n// in every place where we use this component with react-sortable-hoc.\n// (the custom callback with all the logic from default callback, but without button event cancelation).\n// So we decided that just changing it to the div, as it was in v3, is a better fix.\n//\n// default shouldCancelStart callback:\n// https://github.com/clauderic/react-sortable-hoc/blob/d94ba3cc67cfc7d6d460b585e7723bdb50015e53/src/SortableContainer/defaultShouldCancelStart.js\nconst DRAG_HANDLE_DEFAULT_TAG = 'div';\n\nexport interface DragHandleInternalProps extends CommonProps {\n /**\n * The element used for the root node\n * @default div\n */\n as?: 'button' | 'div';\n /**\n * Applies styling for when the component is actively being dragged by\n * the user\n */\n isActive?: boolean;\n /**\n * Applies focus styling\n */\n isFocused?: boolean;\n /**\n * Applies hover styling\n */\n isHovered?: boolean;\n /**\n * Label rendered in DragHandle - not visible on screen as its purpose\n * is for screen readers only\n */\n label: string;\n /**\n * Set type button for div element\n */\n type?: string;\n}\n\nexport type DragHandleProps<\n E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG,\n> = PolymorphicProps<DragHandleInternalProps, E>;\n\nfunction _DragHandle<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG>(\n props: DragHandleProps<E>,\n ref: Ref<any>,\n) {\n const styles = getStyles();\n const {\n as = DRAG_HANDLE_DEFAULT_TAG,\n className,\n isActive,\n isFocused: isFocusedProp,\n isHovered: isHoveredProp,\n label,\n onBlur,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n testId = 'cf-ui-drag-handle',\n style,\n ...otherProps\n } = props;\n const [isFocused, setisFocused] = useState(isFocusedProp);\n const [isHovered, setisHovered] = useState(isHoveredProp);\n\n const handleFocus = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(true);\n\n if (onFocus) {\n onFocus(event);\n }\n },\n [onFocus],\n );\n\n const handleBlur = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(false);\n\n if (onBlur) {\n onBlur(event);\n }\n },\n [onBlur],\n );\n\n const handleMouseEnter = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(true);\n\n if (onMouseEnter) {\n onMouseEnter(event);\n }\n },\n [onMouseEnter],\n );\n\n const handleMouseLeave = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(false);\n\n if (onMouseLeave) {\n onMouseLeave(event);\n }\n },\n [onMouseLeave],\n );\n\n const commonProps = {\n className: cx(styles.root({ isActive, isFocused, isHovered }), className),\n 'data-test-id': testId,\n onBlur: handleBlur,\n onFocus: handleFocus,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n ref,\n style,\n };\n\n if (as === 'div') {\n return (\n <div {...otherProps} {...commonProps} role=\"button\" tabIndex={0}>\n <DragIcon variant=\"muted\" />\n <span className={styles.label}>{label}</span>\n </div>\n );\n }\n\n return (\n <button {...otherProps} {...commonProps} type=\"button\">\n <DragIcon variant=\"muted\" />\n <span className={styles.label}>{label}</span>\n </button>\n );\n}\n\nexport const DragHandle: PolymorphicComponent<\n ExpandProps<DragHandleInternalProps>,\n typeof DRAG_HANDLE_DEFAULT_TAG,\n 'disabled'\n> = React.forwardRef(_DragHandle);\n","import { cx, css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = () => ({\n label: css({\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: 0,\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n border: 0,\n }),\n root: ({\n isActive,\n isFocused,\n isHovered,\n }: {\n isActive: boolean;\n isFocused: boolean;\n isHovered: boolean;\n }) => {\n return cx(\n css({\n alignItems: 'center',\n backgroundColor: tokens.gray100,\n border: 0,\n borderBottomLeftRadius: tokens.borderRadiusMedium,\n borderRight: `1px solid ${tokens.gray200}`,\n borderTopLeftRadius: tokens.borderRadiusMedium,\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n padding: 0,\n position: 'relative',\n transition: `background-color ${tokens.transitionDurationDefault} ${tokens.transitionEasingDefault}`,\n width: tokens.spacingL,\n '&:hover': {\n backgroundColor: tokens.gray200,\n },\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowPrimary,\n },\n }),\n (isActive || isFocused || isHovered) &&\n css({\n backgroundColor: tokens.gray200,\n cursor: isActive ? 'grabbing' : 'grab',\n }),\n );\n },\n});\n"]}
1
+ {"version":3,"sources":["../src/DragHandle.tsx","../src/DragHandle.styles.ts"],"names":["React","useCallback","useState","cx","tokens","DotsSixVerticalIcon","css","hexToRGBA","getStyles","isActive","isFocused","isHovered","variant","DRAG_HANDLE_DEFAULT_TAG","_DragHandle","props","ref","styles","_a","as","className","isFocusedProp","isHoveredProp","label","onBlur","onFocus","onMouseEnter","onMouseLeave","testId","style","otherProps","__objRest","setisFocused","setisHovered","handleFocus","event","handleBlur","handleMouseEnter","handleMouseLeave","commonProps","__spreadProps","__spreadValues","DragHandle"],"mappings":"+kBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAKK,QACP,OAAS,MAAAC,MAAU,UACnB,OAAOC,MAAY,yBAOnB,OAAS,uBAAAC,MAA2B,wBChBpC,OAAS,MAAAF,EAAI,OAAAG,MAAW,UACxB,OAAOF,MAAY,yBACnB,OAAS,aAAAG,MAAiB,wBAGnB,IAAMC,EAAY,KAAO,CAC9B,MAAOF,EAAI,CACT,SAAU,WACV,MAAO,MACP,OAAQ,MACR,QAAS,EACT,OAAQ,OACR,SAAU,SACV,KAAM,mBACN,OAAQ,CACV,CAAC,EACD,KAAM,CAAC,CACL,SAAAG,EACA,UAAAC,EACA,UAAAC,EACA,QAAAC,CACF,IAMST,EACLG,EAAI,CACF,WAAY,SACZ,gBAAiB,cACjB,OAAQ,EACR,UAAW,aACX,QAAS,OACT,eAAgB,S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ACFA,EAAOW,CAAK,CAEhB,EACA,CAACX,CAAM,CACT,EAEMa,EAAmBpC,EACtBkC,GAAU,CACTF,EAAa,EAAI,EAEbP,GACFA,EAAaS,CAAK,CAEtB,EACA,CAACT,CAAY,CACf,EAEMY,EAAmBrC,EACtBkC,GAAU,CACTF,EAAa,EAAK,EAEdN,GACFA,EAAaQ,CAAK,CAEtB,EACA,CAACR,CAAY,CACf,EAEMY,EAAc,CAClB,UAAWpC,EACTc,EAAO,KAAK,CAAE,SAAAR,EAAU,UAAAC,EAAW,UAAAC,EAAW,QAAAC,CAAQ,CAAC,EACvDQ,CACF,EACA,eAAgBQ,EAChB,OAAQQ,EACR,QAASF,EACT,aAAcG,EACd,aAAcC,EACd,IAAAtB,EACA,MAAAa,CACF,EAEA,OAAIV,IAAO,MAEPnB,EAAA,cAAC,MAAAwC,EAAAC,IAAA,GAAQX,GAAgBS,GAAxB,CAAqC,KAAK,SAAS,SAAU,IAC5DvC,EAAA,cAACK,EAAA,CAAoB,MAAOD,EAAO,QAAS,EAC5CJ,EAAA,cAAC,QAAK,UAAWiB,EAAO,OAAQM,CAAM,CACxC,EAKFvB,EAAA,cAAC,SAAAwC,EAAAC,IAAA,GAAWX,GAAgBS,GAA3B,CAAwC,KAAK,WAC5CvC,EAAA,cAACK,EAAA,CAAoB,MAAOD,EAAO,QAAS,EAC5CJ,EAAA,cAAC,QAAK,UAAWiB,EAAO,OAAQM,CAAM,CACxC,CAEJ,CAEO,IAAMmB,EAIT1C,EAAM,WAAWc,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type ElementType,\n type FocusEventHandler,\n type MouseEventHandler,\n type Ref,\n} from 'react';\nimport { cx } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport type {\n PolymorphicComponent,\n PolymorphicProps,\n CommonProps,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { DotsSixVerticalIcon } from '@contentful/f36-icons';\n\nimport { getStyles } from './DragHandle.styles';\n\n// We use div instead of a button because react-sortable-hoc lib cancels sorting if the event target is button.\n//\n// The other alternative way to fix it was to pass a custom `shouldCancelStart` callback,\n// in every place where we use this component with react-sortable-hoc.\n// (the custom callback with all the logic from default callback, but without button event cancelation).\n// So we decided that just changing it to the div, as it was in v3, is a better fix.\n//\n// default shouldCancelStart callback:\n// https://github.com/clauderic/react-sortable-hoc/blob/d94ba3cc67cfc7d6d460b585e7723bdb50015e53/src/SortableContainer/defaultShouldCancelStart.js\nconst DRAG_HANDLE_DEFAULT_TAG = 'div';\n\nexport interface DragHandleInternalProps extends CommonProps {\n /**\n * The element used for the root node\n * @default div\n */\n as?: 'button' | 'div';\n /**\n * Applies styling for when the component is actively being dragged by\n * the user\n */\n isActive?: boolean;\n /**\n * Applies focus styling\n */\n isFocused?: boolean;\n /**\n * Applies hover styling\n */\n isHovered?: boolean;\n /**\n * Label rendered in DragHandle - not visible on screen as its purpose\n * is for screen readers only\n */\n label: string;\n /**\n * Set type button for div element\n */\n type?: string;\n\n /**\n * Determines style variation\n * @default secondary\n */\n variant?: 'secondary' | 'transparent';\n}\n\nexport type DragHandleProps<\n E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG,\n> = PolymorphicProps<DragHandleInternalProps, E>;\n\nfunction _DragHandle<E extends ElementType = typeof DRAG_HANDLE_DEFAULT_TAG>(\n props: DragHandleProps<E>,\n ref: Ref<any>,\n) {\n const styles = getStyles();\n const {\n as = DRAG_HANDLE_DEFAULT_TAG,\n className,\n isActive,\n isFocused: isFocusedProp,\n isHovered: isHoveredProp,\n label,\n onBlur,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n testId = 'cf-ui-drag-handle',\n style,\n variant = 'secondary',\n ...otherProps\n } = props;\n const [isFocused, setisFocused] = useState(isFocusedProp);\n const [isHovered, setisHovered] = useState(isHoveredProp);\n\n const handleFocus = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(true);\n\n if (onFocus) {\n onFocus(event);\n }\n },\n [onFocus],\n );\n\n const handleBlur = useCallback<FocusEventHandler<HTMLElement>>(\n (event) => {\n setisFocused(false);\n\n if (onBlur) {\n onBlur(event);\n }\n },\n [onBlur],\n );\n\n const handleMouseEnter = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(true);\n\n if (onMouseEnter) {\n onMouseEnter(event);\n }\n },\n [onMouseEnter],\n );\n\n const handleMouseLeave = useCallback<MouseEventHandler<HTMLElement>>(\n (event) => {\n setisHovered(false);\n\n if (onMouseLeave) {\n onMouseLeave(event);\n }\n },\n [onMouseLeave],\n );\n\n const commonProps = {\n className: cx(\n styles.root({ isActive, isFocused, isHovered, variant }),\n className,\n ),\n 'data-test-id': testId,\n onBlur: handleBlur,\n onFocus: handleFocus,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n ref,\n style,\n };\n\n if (as === 'div') {\n return (\n <div {...otherProps} {...commonProps} role=\"button\" tabIndex={0}>\n <DotsSixVerticalIcon color={tokens.gray600} />\n <span className={styles.label}>{label}</span>\n </div>\n );\n }\n\n return (\n <button {...otherProps} {...commonProps} type=\"button\">\n <DotsSixVerticalIcon color={tokens.gray600} />\n <span className={styles.label}>{label}</span>\n </button>\n );\n}\n\nexport const DragHandle: PolymorphicComponent<\n ExpandProps<DragHandleInternalProps>,\n typeof DRAG_HANDLE_DEFAULT_TAG,\n 'disabled'\n> = React.forwardRef(_DragHandle);\n","import { cx, css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { hexToRGBA } from '@contentful/f36-utils';\nimport { DragHandleProps } from './DragHandle';\n\nexport const getStyles = () => ({\n label: css({\n position: 'absolute',\n width: '1px',\n height: '1px',\n padding: 0,\n margin: '-1px',\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n border: 0,\n }),\n root: ({\n isActive,\n isFocused,\n isHovered,\n variant,\n }: {\n isActive: boolean;\n isFocused: boolean;\n isHovered: boolean;\n variant: DragHandleProps['variant'];\n }) => {\n return cx(\n css({\n alignItems: 'center',\n backgroundColor: 'transparent',\n border: 0,\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n padding: 0,\n margin: 0, // remove the default button margin in Safari.\n position: 'relative',\n transition: `background-color ${tokens.transitionDurationDefault} ${tokens.transitionEasingDefault}`,\n width: tokens.spacingL,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowPrimary,\n },\n }),\n variant === 'secondary' &&\n css({\n borderRight: `1px solid ${tokens.gray200}`,\n borderTopLeftRadius: tokens.borderRadiusMedium,\n borderBottomLeftRadius: tokens.borderRadiusMedium,\n backgroundColor: tokens.gray100,\n '&:hover': {\n backgroundColor: hexToRGBA(tokens.gray900, 0.08),\n },\n }),\n variant === 'secondary' &&\n (isActive || isFocused || isHovered) &&\n css({\n backgroundColor: hexToRGBA(tokens.gray900, 0.08),\n }),\n (isActive || isFocused || isHovered) &&\n css({\n cursor: isActive ? 'grabbing' : 'grab',\n }),\n );\n },\n});\n"]}
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@contentful/f36-drag-handle",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "description": "Forma 36: DragHandle component",
5
5
  "scripts": {
6
6
  "build": "tsup"
7
7
  },
8
8
  "dependencies": {
9
- "@contentful/f36-core": "^5.0.0",
10
- "@contentful/f36-icons": "^5.0.0",
11
- "@contentful/f36-tokens": "^4.0.1",
9
+ "@contentful/f36-core": "^5.1.1",
10
+ "@contentful/f36-icons": "^5.1.1",
11
+ "@contentful/f36-utils": "^5.1.0",
12
+ "@contentful/f36-tokens": "^5.1.0",
12
13
  "emotion": "^10.0.17"
13
14
  },
14
15
  "peerDependencies": {
15
- "react": ">=16.8"
16
+ "react": ">=16.8",
17
+ "react-dom": ">=16.8"
16
18
  },
17
19
  "license": "MIT",
18
20
  "files": [
@@ -26,9 +28,10 @@
26
28
  "browserslist": "extends @contentful/browserslist-config",
27
29
  "repository": {
28
30
  "type": "git",
29
- "url": "https://github.com/contentful/forma-36"
31
+ "url": "git+https://github.com/contentful/forma-36.git"
30
32
  },
31
33
  "publishConfig": {
34
+ "registry": "https://npm.pkg.github.com/",
32
35
  "access": "public"
33
36
  }
34
37
  }