@platformatic/ui-components 0.1.24 → 0.1.26

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@platformatic/ui-components",
3
3
  "description": "Platformatic UI Components",
4
- "version": "0.1.24",
4
+ "version": "0.1.26",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -16,7 +16,7 @@
16
16
  @apply hover:cursor-pointer
17
17
  }
18
18
  .menu {
19
- @apply absolute border-solid border border-main-green p-4 bg-dark-blue mt-8 rounded-md;
19
+ @apply absolute border-solid border border-main-green p-4 bg-dark-blue mt-8 rounded-md z-[999];
20
20
  }
21
21
  .item {
22
22
  @apply mb-2
@@ -1,9 +1,11 @@
1
1
  import { faClose } from '@fortawesome/free-solid-svg-icons'
2
2
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
3
  import React from 'react'
4
+ import useEscapeKey from '../hooks/useEscapeKey'
4
5
  import styles from './Modal.module.css'
5
6
  export default function Modal (props) {
6
7
  const { setIsOpen, title } = props
8
+ useEscapeKey(() => setIsOpen(false))
7
9
  return (
8
10
  <>
9
11
  <div className={styles.blur} onClick={() => setIsOpen(false)} />
@@ -1,7 +1,10 @@
1
1
  .blur {
2
- @apply absolute top-[50%] left-[50%] z-0 w-[100vw] h-[100vh] translate-x-[-50%] translate-y-[-50%];
2
+ @apply absolute top-[50%] left-[50%] z-0 w-[100vw] h-[100vh] translate-x-[-50%] translate-y-[-50%] z-[9999];
3
3
  background-color: rgba(0, 0, 0, 0.75);
4
4
  }
5
+ .container {
6
+ @apply z-[9999];
7
+ }
5
8
  .centered {
6
9
  @apply fixed top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]
7
10
  }
@@ -0,0 +1,20 @@
1
+ import { useCallback, useEffect } from 'react'
2
+ const KEY_NAME_ESC = 'Escape'
3
+ const KEY_EVENT_TYPE = 'keyup'
4
+ function useEscapeKey (handleClose) {
5
+ const handleEscKey = useCallback((event) => {
6
+ if (event.key === KEY_NAME_ESC) {
7
+ handleClose()
8
+ }
9
+ }, [handleClose])
10
+
11
+ useEffect(() => {
12
+ document.addEventListener(KEY_EVENT_TYPE, handleEscKey, false)
13
+
14
+ return () => {
15
+ document.removeEventListener(KEY_EVENT_TYPE, handleEscKey, false)
16
+ }
17
+ }, [handleEscKey])
18
+ }
19
+
20
+ export default useEscapeKey
@@ -1,12 +1,31 @@
1
1
  'use strict'
2
2
  import DropDown from '../components/DropDown'
3
+ import BorderedBox from '../components/BorderedBox'
4
+ import HorizontalSeparator from '../components/HorizontalSeparator'
5
+ import { useState } from 'react'
3
6
  export default {
4
7
  title: 'Platformatic/DropDown',
5
8
  component: DropDown,
6
9
  decorators: [dd => <div className='text-white'>{dd()}</div>]
7
10
  }
8
11
 
9
- const Template = (args) => <DropDown {...args} />
12
+ const Template = (args) => (
13
+ <div>
14
+ <DropDown {...args} />
15
+ <HorizontalSeparator />
16
+ <ContentThatLoads />
17
+ </div>
18
+ )
19
+
20
+ const ContentThatLoads = () => {
21
+ const [content, setContent] = useState(null)
22
+ setTimeout(() => {
23
+ setContent(<div className='mt-4'><BorderedBox>This is rendered after</BorderedBox></div>)
24
+ }, 1000)
25
+
26
+ return content
27
+ }
28
+
10
29
  export const DefaultAlignment = Template.bind({})
11
30
 
12
31
  DefaultAlignment.args = {
@@ -1,6 +1,9 @@
1
1
  import React, { useState } from 'react'
2
2
  import Modal from '../components/Modal'
3
3
  import Button from '../components/Button'
4
+ import BorderedBox from '../components/BorderedBox'
5
+ import DropDown from '../components/DropDown'
6
+ import HorizontalSeparator from '../components/HorizontalSeparator'
4
7
  export default {
5
8
  title: 'Platformatic/Modal',
6
9
  component: Modal
@@ -10,13 +13,43 @@ const Template = (args) => {
10
13
  const [isOpen, setIsOpen] = useState(false)
11
14
  return (
12
15
  <main>
16
+ <BorderedBox>This Is another Content</BorderedBox>
17
+ <ContentThatLoads />
13
18
  <Button color='green' primary='true' onClick={() => setIsOpen(true)} label='Open Modal' />
14
19
  {isOpen && <Modal setIsOpen={setIsOpen} title='Modal Title'>Hello world!</Modal>}
15
20
  </main>
16
21
  )
17
22
  }
18
23
 
24
+ const ContentThatLoads = () => {
25
+ const [content, setContent] = useState(null)
26
+ setTimeout(() => {
27
+ setContent(<div className='mt-4'><BorderedBox>This is a Future Component</BorderedBox></div>)
28
+ }, 1000)
29
+
30
+ return content
31
+ }
32
+
19
33
  export const Default = Template.bind({})
20
34
  Default.args = {
21
35
  title: 'List Title'
22
36
  }
37
+
38
+ const MenuTemplate = () => {
39
+ const [isOpen, setIsOpen] = useState(false)
40
+ const dropDownArgs = {
41
+ header: 'My Menu',
42
+ items: [
43
+ <span className='hover:cursor-pointer' key='2' onClick={() => setIsOpen(true)}>Show Modal</span>
44
+ ]
45
+ }
46
+ return (
47
+ <div>
48
+ <div className='text-white'><DropDown {...dropDownArgs} /></div>
49
+ <HorizontalSeparator />
50
+ {isOpen && <Modal setIsOpen={setIsOpen} title='Modal Title'>Hello world!</Modal>}
51
+ <ContentThatLoads />
52
+ </div>
53
+ )
54
+ }
55
+ export const WithDropDown = MenuTemplate.bind({})