playbook_ui 14.17.0.pre.alpha.play2065passphrasewithselect7273 → 14.17.0.pre.alpha.play2065passphrasewithselect7295
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_copy_button/_copy_button.tsx +19 -45
- data/app/pb_kits/playbook/pb_copy_button/docs/_copy_button_hook.jsx +54 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/_copy_button_hook.md +3 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_copy_button/usePBCopy.ts +45 -0
- data/dist/chunks/{_typeahead-BY6AFq1l.js → _typeahead-CHd0V9EL.js} +1 -1
- data/dist/chunks/_weekday_stacked-BatiLk3-.js +45 -0
- data/dist/chunks/{lib-BGzBzFZX.js → lib-BV_AF_eh.js} +3 -3
- data/dist/chunks/{pb_form_validation-BvNy9Bd6.js → pb_form_validation-nsvkJU2J.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +9 -6
- data/dist/chunks/_weekday_stacked-BwWArBYi.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80adca99d2382dccb2127f505af545b8ac11a47c828ea2307145fde157b3ca21
|
4
|
+
data.tar.gz: c7006296bae96b85063e72574f45b750a1eb548372853a31d469866da2b4ff89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47b0288480e008f857dc8f41067c51707344035f8b487eab5bf317ec4d4194fbadbed7cc2c53ec6ea8cb2ef297bcebc4071ac8237bcfa1b0f638c7242982772d
|
7
|
+
data.tar.gz: a1de55141eea889f3d1201b60b8060e3cf2dd4a706854c5ee783c5d6ea46b42862cf52be1d3b6447136b09ef18eb49c4b35df96f0a60d70688cc623ac8ce8d76
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
import React, { useState } from 'react'
|
1
|
+
import React from 'react'
|
3
2
|
import classnames from 'classnames'
|
4
3
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
5
4
|
import { globalProps } from '../utilities/globalProps'
|
@@ -7,16 +6,19 @@ import { globalProps } from '../utilities/globalProps'
|
|
7
6
|
import Button from '../pb_button/_button'
|
8
7
|
import Tooltip from '../pb_tooltip/_tooltip'
|
9
8
|
|
9
|
+
import usePBCopy from './usePBCopy'
|
10
|
+
|
10
11
|
type CopyButtonProps = {
|
11
|
-
aria?: { [key: string]: string }
|
12
|
-
className?: string
|
13
|
-
data?: { [key: string]: string }
|
14
|
-
id?: string
|
15
|
-
from?: string
|
16
|
-
text?: string
|
17
|
-
tooltipPlacement?:
|
18
|
-
tooltipText?: string
|
19
|
-
value?: string
|
12
|
+
aria?: { [key: string]: string }
|
13
|
+
className?: string
|
14
|
+
data?: { [key: string]: string }
|
15
|
+
id?: string
|
16
|
+
from?: string
|
17
|
+
text?: string
|
18
|
+
tooltipPlacement?: 'top' | 'right' | 'bottom' | 'left'
|
19
|
+
tooltipText?: string
|
20
|
+
value?: string
|
21
|
+
timeout?: number
|
20
22
|
}
|
21
23
|
|
22
24
|
const CopyButton = (props: CopyButtonProps) => {
|
@@ -27,62 +29,34 @@ const CopyButton = (props: CopyButtonProps) => {
|
|
27
29
|
from = '',
|
28
30
|
id,
|
29
31
|
text= 'Copy',
|
32
|
+
timeout = 1000,
|
30
33
|
tooltipPlacement= 'bottom',
|
31
34
|
tooltipText = 'Copied!',
|
32
35
|
value = '',
|
33
36
|
} = props
|
34
37
|
|
35
|
-
const [copied,
|
38
|
+
const [copied, copy] = usePBCopy({ value, from, timeout })
|
36
39
|
|
37
40
|
const ariaProps = buildAriaProps(aria)
|
38
41
|
const dataProps = buildDataProps(data)
|
39
42
|
const classes = classnames(buildCss('pb_copy_button_kit'), globalProps(props), className)
|
40
43
|
|
41
|
-
const copy = () => {
|
42
|
-
if (!from && !value) {
|
43
|
-
return
|
44
|
-
}
|
45
|
-
|
46
|
-
if (value) {
|
47
|
-
navigator.clipboard.writeText(value)
|
48
|
-
} else if (from) {
|
49
|
-
const copyElement = document.getElementById(from);
|
50
|
-
let copyText = copyElement?.innerText
|
51
|
-
|
52
|
-
if (copyElement instanceof HTMLTextAreaElement || copyElement instanceof HTMLInputElement) {
|
53
|
-
copyText = copyElement.value;
|
54
|
-
}
|
55
|
-
|
56
|
-
if (copyText) {
|
57
|
-
navigator.clipboard.writeText(copyText)
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
setCopied(true)
|
62
|
-
|
63
|
-
setTimeout(() => {
|
64
|
-
setCopied(false)
|
65
|
-
}, 1000);
|
66
|
-
}
|
67
|
-
|
68
44
|
return (
|
69
|
-
<div
|
70
|
-
{...ariaProps}
|
45
|
+
<div {...ariaProps}
|
71
46
|
{...dataProps}
|
72
47
|
className={classes}
|
73
48
|
id={id}
|
74
49
|
>
|
75
|
-
<Tooltip
|
50
|
+
<Tooltip
|
76
51
|
forceOpenTooltip={copied}
|
77
52
|
placement={tooltipPlacement}
|
78
53
|
showTooltip={false}
|
79
54
|
text={tooltipText}
|
80
55
|
>
|
81
|
-
<Button
|
82
|
-
icon='copy'
|
56
|
+
<Button icon="copy"
|
83
57
|
onClick={copy}
|
84
58
|
>
|
85
|
-
{
|
59
|
+
{text}
|
86
60
|
</Button>
|
87
61
|
</Tooltip>
|
88
62
|
</div>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
2
|
+
import usePBCopy from '../../pb_copy_button/usePBCopy'
|
3
|
+
import Body from '../../pb_body/_body'
|
4
|
+
import Textarea from '../../pb_textarea/_textarea'
|
5
|
+
import Tooltip from '../../pb_tooltip/_tooltip'
|
6
|
+
|
7
|
+
const CopyButtonHook = ({...props}) => {
|
8
|
+
// This is how you can use the copy button hook to copy text to the clipboard
|
9
|
+
// eslint-disable-next-line no-unused-vars
|
10
|
+
const [copied, copyToClipboard] = usePBCopy({ from: 'hookbody' })
|
11
|
+
// I added a tooltip so it looks better in the ui
|
12
|
+
const [showTooltip, setShowTooltip] = useState(false)
|
13
|
+
|
14
|
+
const handleCopy = () => {
|
15
|
+
copyToClipboard()
|
16
|
+
setShowTooltip(true)
|
17
|
+
setTimeout(() => setShowTooltip(false), 1500)
|
18
|
+
}
|
19
|
+
|
20
|
+
useEffect(() => {
|
21
|
+
const el = document.getElementById('hookbody')
|
22
|
+
if (!el) return
|
23
|
+
|
24
|
+
el.addEventListener('click', handleCopy)
|
25
|
+
return () => {
|
26
|
+
el.removeEventListener('click', handleCopy)
|
27
|
+
}
|
28
|
+
}, [copyToClipboard])
|
29
|
+
|
30
|
+
return (
|
31
|
+
<div>
|
32
|
+
<Tooltip
|
33
|
+
delay={{ close: 1000 }}
|
34
|
+
forceOpenTooltip={showTooltip}
|
35
|
+
placement="top"
|
36
|
+
showTooltip={false}
|
37
|
+
text="Copied!"
|
38
|
+
>
|
39
|
+
<Body
|
40
|
+
cursor="pointer"
|
41
|
+
id="hookbody"
|
42
|
+
text="I'm a custom copy hook! Click this body to copy this text!"
|
43
|
+
/>
|
44
|
+
</Tooltip>
|
45
|
+
|
46
|
+
<Textarea
|
47
|
+
{...props}
|
48
|
+
placeholder="Paste here"
|
49
|
+
/>
|
50
|
+
</div>
|
51
|
+
)
|
52
|
+
}
|
53
|
+
|
54
|
+
export default CopyButtonHook
|
@@ -0,0 +1,3 @@
|
|
1
|
+
We provide a `usePBCopy` hook that you can import to your project. This hook will return a function that you can call to copy the text to the clipboard.
|
2
|
+
|
3
|
+
`usePBCopy({ from: 'your_id' })` will grab the `innerText` from `your_id` element, or `value` if it is an input element.
|
@@ -1,2 +1,3 @@
|
|
1
1
|
export { default as CopyButtonDefault } from './_copy_button_default.jsx'
|
2
|
-
export { default as CopyButtonFrom } from './_copy_button_from.jsx'
|
2
|
+
export { default as CopyButtonFrom } from './_copy_button_from.jsx'
|
3
|
+
export { default as CopyButtonHook } from './_copy_button_hook.jsx'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { useState, useRef, useEffect } from 'react'
|
2
|
+
|
3
|
+
type UsePBCopyProps = {
|
4
|
+
value?: string
|
5
|
+
from?: string
|
6
|
+
timeout?: number
|
7
|
+
}
|
8
|
+
|
9
|
+
export default function usePBCopy({
|
10
|
+
value = '',
|
11
|
+
from = '',
|
12
|
+
timeout = 0,
|
13
|
+
}: UsePBCopyProps) {
|
14
|
+
const [copied, setCopied] = useState(false)
|
15
|
+
const timerRef = useRef<number>()
|
16
|
+
|
17
|
+
const copy = () => {
|
18
|
+
if (!value && !from) return
|
19
|
+
|
20
|
+
if (value) {
|
21
|
+
navigator.clipboard.writeText(value)
|
22
|
+
} else {
|
23
|
+
const el = document.getElementById(from)
|
24
|
+
let text = el?.innerText
|
25
|
+
if (el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement) {
|
26
|
+
text = el.value
|
27
|
+
}
|
28
|
+
if (text) navigator.clipboard.writeText(text)
|
29
|
+
}
|
30
|
+
|
31
|
+
setCopied(true)
|
32
|
+
window.clearTimeout(timerRef.current)
|
33
|
+
timerRef.current = window.setTimeout(() => {
|
34
|
+
setCopied(false)
|
35
|
+
}, timeout)
|
36
|
+
}
|
37
|
+
|
38
|
+
useEffect(() => {
|
39
|
+
return () => {
|
40
|
+
window.clearTimeout(timerRef.current)
|
41
|
+
}
|
42
|
+
}, [])
|
43
|
+
|
44
|
+
return [copied, copy] as const
|
45
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useRef,useState,useEffect,useMemo,useContext,createElement,forwardRef,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{
|
1
|
+
import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useRef,useState,useEffect,useMemo,useContext,createElement,forwardRef,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{s as getDefaultExportFromCjs,y as filter,z as omit,u as useCollapsible,A as get,j as getAllIcons,r as commonjsGlobal,x as colors$1,v as highchartsTheme,B as merge,t as highchartsDarkTheme,C as offset$2,E as shift$2,F as flip$2,G as computePosition$1,H as arrow$3,I as createCoords$1,J as round$1,K as max$1,L as min$1,M as rectToClientRect$1,N as getAugmentedNamespace,O as createPopper,Q as uniqueId,S as typography,T as cloneDeep,m as isEmpty$1,U as isString}from"./lib-BV_AF_eh.js";import*as ReactDOM from"react-dom";import ReactDOM__default,{createPortal}from"react-dom";import{TrixEditor}from"react-trix";import Trix from"trix";import require$$0 from"react-is";const initialState={items:[],dragData:{id:"",initialGroup:""},isDragging:"",activeContainer:""};const reducer=(state,action)=>{switch(action.type){case"SET_ITEMS":return{...state,items:action.payload};case"SET_DRAG_DATA":return{...state,dragData:action.payload};case"SET_IS_DRAGGING":return{...state,isDragging:action.payload};case"SET_ACTIVE_CONTAINER":return{...state,activeContainer:action.payload};case"CHANGE_CATEGORY":return{...state,items:state.items.map((item=>item.id===action.payload.itemId?{...item,container:action.payload.container}:item))};case"REORDER_ITEMS":{const{dragId:dragId,targetId:targetId}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item.id===dragId));const targetItem=newItems.find((item=>item.id===targetId));if(!draggedItem||!targetItem||draggedItem.container!==targetItem.container){return state}if(dragId===targetId){return state}const draggedIndex=newItems.findIndex((item=>item.id===dragId));const targetIndex=newItems.findIndex((item=>item.id===targetId));if(draggedIndex===-1||targetIndex===-1){return state}newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,draggedItem);return{...state,items:newItems}}default:return state}};const DragContext=createContext({});const DraggableContext=()=>{const context=useContext(DragContext);if(context===void 0){throw new Error("DraggableContext must be used within a DraggableProvider")}return context};const DraggableProvider=({children:children,initialItems:initialItems,onReorder:onReorder,onDragStart:onDragStart,onDragEnter:onDragEnter,onDragEnd:onDragEnd,onDrop:onDrop,onDragOver:onDragOver,dropZone:dropZone={type:"ghost",color:"neutral",direction:"vertical"}})=>{const[state,dispatch]=useReducer(reducer,initialState);const initialItemsRef=useRef(initialItems);const[isDragging,setIsDragging]=useState(false);let dropZoneType="ghost";let dropZoneColor="neutral";let dropZoneDirection="vertical";if(typeof dropZone==="string"){dropZoneType=dropZone}else{dropZoneType=dropZone.type||"ghost";dropZoneColor=dropZone.type==="line"?dropZone.color||"primary":dropZone.color||"neutral";if(dropZoneType==="line"){dropZoneDirection=dropZone.direction||"vertical"}}useEffect((()=>{dispatch({type:"SET_ITEMS",payload:initialItems});initialItemsRef.current=initialItems}),[initialItems]);useEffect((()=>{if(onReorder){onReorder(state.items)}}),[state.items,onReorder]);const handleDragStart=(id,container)=>{setIsDragging(true);dispatch({type:"SET_DRAG_DATA",payload:{id:id,initialGroup:container}});dispatch({type:"SET_IS_DRAGGING",payload:id});dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(!isDragging||container!==state.activeContainer)return;if(state.dragData.id===id)return;const draggedItem=state.items.find((item=>item.id===state.dragData.id));const targetItem=state.items.find((item=>item.id===id));if(!draggedItem||!targetItem||draggedItem.container!==targetItem.container){return}dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}});if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{setIsDragging(false);dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});if(onDragEnd)onDragEnd()};const handleDrop=container=>{const draggedItem=state.items.find((item=>item.id===state.dragData.id));if(draggedItem&&draggedItem.container!==container){dispatch({type:"CHANGE_CATEGORY",payload:{itemId:state.dragData.id,container:container}})}dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});setIsDragging(false);if(onDrop)onDrop(container)};const handleDragOver=(e,container)=>{e.preventDefault();e.stopPropagation();dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(onDragOver)onDragOver(e,container)};const contextValue=useMemo((()=>({items:state.items,dragData:state.dragData,isDragging:state.isDragging,activeContainer:state.activeContainer,dropZone:dropZoneType,dropZoneColor:dropZoneColor,...dropZoneType==="line"?{direction:dropZoneDirection}:{},handleDragStart:handleDragStart,handleDragEnter:handleDragEnter,handleDragEnd:handleDragEnd,handleDrop:handleDrop,handleDragOver:handleDragOver})),[state,dropZoneType,dropZoneColor,dropZoneDirection,handleDragStart,handleDragEnter,handleDragEnd,handleDrop,handleDragOver]);return jsx$1(DragContext.Provider,{value:contextValue,children:children})};var classnames$1={exports:{}};
|
2
2
|
/*!
|
3
3
|
Copyright (c) 2018 Jed Watson.
|
4
4
|
Licensed under the MIT License (MIT), see
|