@charcoal-ui/react 3.0.0-beta.0 → 3.0.0-beta.2

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.
Files changed (41) hide show
  1. package/dist/components/Button/index.d.ts.map +1 -1
  2. package/dist/components/DropdownSelector/DropdownPopover.d.ts.map +1 -1
  3. package/dist/components/DropdownSelector/OptionItem.d.ts +7 -0
  4. package/dist/components/DropdownSelector/OptionItem.d.ts.map +1 -0
  5. package/dist/components/DropdownSelector/index.d.ts +22 -29
  6. package/dist/components/DropdownSelector/index.d.ts.map +1 -1
  7. package/dist/components/DropdownSelector/index.story.d.ts +5 -18
  8. package/dist/components/DropdownSelector/index.story.d.ts.map +1 -1
  9. package/dist/components/DropdownSelector/utils/focusIfHTMLLIElement.d.ts +6 -0
  10. package/dist/components/DropdownSelector/utils/focusIfHTMLLIElement.d.ts.map +1 -0
  11. package/dist/components/DropdownSelector/utils/handleFocusByKeyBoard.d.ts +6 -0
  12. package/dist/components/DropdownSelector/utils/handleFocusByKeyBoard.d.ts.map +1 -0
  13. package/dist/components/LoadingSpinner/index.d.ts.map +1 -1
  14. package/dist/components/Modal/index.d.ts +5 -2
  15. package/dist/components/Modal/index.d.ts.map +1 -1
  16. package/dist/components/Radio/index.d.ts.map +1 -1
  17. package/dist/components/SegmentedControl/index.d.ts.map +1 -1
  18. package/dist/components/SegmentedControl/index.story.d.ts.map +1 -1
  19. package/dist/index.cjs.js +313 -336
  20. package/dist/index.cjs.js.map +1 -1
  21. package/dist/index.d.ts +3 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.esm.js +296 -319
  24. package/dist/index.esm.js.map +1 -1
  25. package/package.json +6 -6
  26. package/src/components/DropdownSelector/DropdownPopover.tsx +9 -15
  27. package/src/components/DropdownSelector/OptionItem.tsx +85 -0
  28. package/src/components/DropdownSelector/index.story.tsx +69 -156
  29. package/src/components/DropdownSelector/index.tsx +110 -140
  30. package/src/components/DropdownSelector/utils/focusIfHTMLLIElement.tsx +12 -0
  31. package/src/components/DropdownSelector/utils/handleFocusByKeyBoard.tsx +20 -0
  32. package/src/components/LoadingSpinner/index.tsx +1 -0
  33. package/src/components/Modal/index.tsx +79 -61
  34. package/src/components/Radio/index.tsx +2 -0
  35. package/src/components/SegmentedControl/index.story.tsx +2 -0
  36. package/src/components/SegmentedControl/index.tsx +1 -0
  37. package/src/components/TextField/index.tsx +1 -0
  38. package/src/index.ts +7 -2
  39. package/src/components/DropdownSelector/ListBoxSection.tsx +0 -60
  40. package/src/components/DropdownSelector/Listbox.tsx +0 -67
  41. package/src/components/DropdownSelector/Option.tsx +0 -66
@@ -1,67 +0,0 @@
1
- import React, { memo, useRef, Fragment, useMemo } from 'react'
2
- import styled from 'styled-components'
3
- import { ListProps, ListState } from 'react-stately'
4
- import { useListBox } from '@react-aria/listbox'
5
- import { theme } from '../../styled'
6
-
7
- import { ListBoxSection } from './ListBoxSection'
8
- import { Divider } from './Divider'
9
- import { Option } from './Option'
10
-
11
- export type ListMode = 'default' | 'separator'
12
- export type ListboxProps<T> = Omit<ListProps<T>, 'children'> & {
13
- state: ListState<T>
14
- mode?: ListMode
15
- }
16
-
17
- const Listbox = <T,>({
18
- state,
19
- mode = 'default',
20
- ...props
21
- }: ListboxProps<T>) => {
22
- const ref = useRef<HTMLUListElement>(null)
23
-
24
- const { listBoxProps } = useListBox(props, state, ref)
25
- const collection = useMemo(
26
- () =>
27
- [...state.collection].map((node, index, self) => ({
28
- node,
29
- first: index === 0,
30
- last: index === self.length - 1,
31
- })),
32
- [state.collection]
33
- )
34
-
35
- return (
36
- <ListboxRoot ref={ref} {...listBoxProps}>
37
- {collection.map(({ node, last }) => (
38
- <Fragment key={node.key}>
39
- {node.type === 'section' ? (
40
- <ListBoxSection section={node} state={state} />
41
- ) : (
42
- <Option item={node} state={state} mode={mode} />
43
- )}
44
- {!last && mode === 'separator' && <Divider />}
45
- </Fragment>
46
- ))}
47
- </ListboxRoot>
48
- )
49
- }
50
- export default memo(Listbox)
51
-
52
- const ListboxRoot = styled.ul`
53
- padding-left: 0;
54
- margin: 0;
55
- box-sizing: border-box;
56
- list-style: none;
57
- overflow: auto;
58
- max-height: inherit;
59
-
60
- ${theme((o) => [
61
- o.bg.background1,
62
- o.border.default,
63
- o.borderRadius(8),
64
- o.padding.vertical(8),
65
- o.outline.default.focus,
66
- ])}
67
- `
@@ -1,66 +0,0 @@
1
- import React, { useRef } from 'react'
2
- import styled, { css } from 'styled-components'
3
- import { ListState } from 'react-stately'
4
- import { useOption } from '@react-aria/listbox'
5
- import { mergeProps } from '@react-aria/utils'
6
- import { useFocusRing } from '@react-aria/focus'
7
- import { px } from '@charcoal-ui/utils'
8
- import Icon from '../Icon'
9
- import { theme } from '../../styled'
10
- import { Node } from '@react-types/shared'
11
- import { ListMode } from './Listbox'
12
-
13
- type OptionProps<T> = {
14
- item: Node<T>
15
- state: ListState<T>
16
- mode?: ListMode
17
- }
18
-
19
- export function Option<T>({ item, state, mode }: OptionProps<T>) {
20
- const ref = useRef<HTMLLIElement>(null)
21
-
22
- const { optionProps, isSelected } = useOption(item, state, ref)
23
- const { focusProps } = useFocusRing()
24
-
25
- return (
26
- <OptionRoot {...mergeProps(optionProps, focusProps)} ref={ref} mode={mode}>
27
- <OptionCheckIcon name="16/Check" isSelected={isSelected} />
28
- <OptionText>{item.rendered}</OptionText>
29
- </OptionRoot>
30
- )
31
- }
32
-
33
- const OptionRoot = styled.li<{ mode?: ListMode }>`
34
- display: flex;
35
- align-items: center;
36
- gap: ${({ theme }) => px(theme.spacing[4])};
37
- height: 40px;
38
- cursor: pointer;
39
- outline: none;
40
-
41
- ${({ mode }) =>
42
- theme((o) => [
43
- o.padding.horizontal(8),
44
- mode === 'separator' && o.padding.vertical(4),
45
- ])}
46
-
47
- &:focus {
48
- ${theme((o) => [o.bg.surface3])}
49
- }
50
- `
51
-
52
- const OptionCheckIcon = styled(Icon)<{ isSelected: boolean }>`
53
- visibility: hidden;
54
- ${theme((o) => [o.font.text2])}
55
-
56
- ${({ isSelected }) =>
57
- isSelected &&
58
- css`
59
- visibility: visible;
60
- `}
61
- `
62
-
63
- const OptionText = styled.span`
64
- display: block;
65
- ${theme((o) => [o.typography(14), o.font.text2])}
66
- `