@teamturing/react-kit 2.8.1 → 2.9.0

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.
@@ -0,0 +1,77 @@
1
+ import { useRef, useState, useEffect } from 'react';
2
+ import styled, { css } from 'styled-components';
3
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
4
+ import Tooltip from '../Tooltip/index.js';
5
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
6
+
7
+ const BreadcrumbsItem = ({
8
+ text,
9
+ selected = false,
10
+ truncatedWidth = 100,
11
+ ...props
12
+ }) => {
13
+ const itemRef = useRef(null);
14
+ const [isOverflow, setIsOverflow] = useState(false);
15
+ useEffect(() => {
16
+ if (itemRef.current) {
17
+ if (truncatedWidth <= itemRef.current.clientWidth) {
18
+ setIsOverflow(true);
19
+ }
20
+ }
21
+ }, []);
22
+ const baseBreadCrumbsItem = /*#__PURE__*/jsxRuntimeExports.jsx(BaseBreadcrumbsItem, {
23
+ ref: itemRef,
24
+ selected: selected,
25
+ truncatedWidth: truncatedWidth,
26
+ ...props,
27
+ children: text
28
+ });
29
+ return isOverflow ? /*#__PURE__*/jsxRuntimeExports.jsx(Tooltip, {
30
+ text: text,
31
+ direction: 'bottom-center',
32
+ sx: {
33
+ display: 'inline-flex'
34
+ },
35
+ children: baseBreadCrumbsItem
36
+ }) : baseBreadCrumbsItem;
37
+ };
38
+ const BaseBreadcrumbsItem = styled.a`
39
+ display: inline-block;
40
+ font-size: ${({
41
+ theme
42
+ }) => forcePixelValue(theme.fontSizes.xxs)};
43
+ font-weight: ${({
44
+ theme
45
+ }) => theme.fontWeights.medium};
46
+ line-height: ${({
47
+ theme
48
+ }) => theme.lineHeights[2]};
49
+ color: ${({
50
+ theme
51
+ }) => theme.colors['text/neutral/subtlest']};
52
+ cursor: pointer;
53
+
54
+ &:hover {
55
+ text-decoration: underline;
56
+ }
57
+
58
+ text-overflow: ellipsis;
59
+ overflow: hidden;
60
+ word-break: break-word;
61
+ white-space: nowrap;
62
+
63
+ max-width: ${({
64
+ truncatedWidth
65
+ }) => truncatedWidth ? forcePixelValue(truncatedWidth) : ''};
66
+
67
+ ${({
68
+ selected
69
+ }) => selected ? css`
70
+ color: ${({
71
+ theme
72
+ }) => theme.colors['text/neutral/subtle']};
73
+ pointer-events: none;
74
+ ` : ''}
75
+ `;
76
+
77
+ export { BreadcrumbsItem as default };
@@ -0,0 +1,72 @@
1
+ import { Children, useState } from 'react';
2
+ import styled from 'styled-components';
3
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
4
+ import BreadcrumbsItem from './BreadcrumbsItem.js';
5
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
6
+
7
+ const Breadcrumbs = ({
8
+ children,
9
+ maxItemCount = 5,
10
+ ...props
11
+ }) => {
12
+ const childrenArray = Children.toArray(children);
13
+ const shouldCollapse = maxItemCount < childrenArray.length;
14
+ const [isExpanded, setIsExpanded] = useState(!shouldCollapse);
15
+ const breadcrumbsItems = isExpanded ? childrenArray : [...childrenArray.slice(0, 1), /*#__PURE__*/jsxRuntimeExports.jsx(BreadcrumbsItem, {
16
+ text: '...',
17
+ onClick: () => setIsExpanded(true)
18
+ }, 'collapse'), ...childrenArray.slice(1 + 1 + childrenArray.length - maxItemCount)];
19
+ return /*#__PURE__*/jsxRuntimeExports.jsx(BaseBreadcrumbs, {
20
+ ...props,
21
+ children: Children.map(breadcrumbsItems, child => /*#__PURE__*/jsxRuntimeExports.jsx(BreadcrumbsItemWrapper, {
22
+ role: 'listitem',
23
+ children: child
24
+ }))
25
+ });
26
+ };
27
+ const BaseBreadcrumbs = styled.nav`
28
+ display: flex;
29
+ align-items: center;
30
+ justify-content: flex-start;
31
+ flex-wrap: wrap;
32
+
33
+ column-gap: ${({
34
+ theme
35
+ }) => forcePixelValue(theme.space[2])};
36
+ row-gap: ${({
37
+ theme
38
+ }) => forcePixelValue(theme.space[1])};
39
+ `;
40
+ const BreadcrumbsItemWrapper = styled.span`
41
+ display: inline-flex;
42
+
43
+ &::after {
44
+ content: '/';
45
+ font-size: ${({
46
+ theme
47
+ }) => forcePixelValue(theme.fontSizes.xxs)};
48
+ font-weight: ${({
49
+ theme
50
+ }) => theme.fontWeights.medium};
51
+ line-height: ${({
52
+ theme
53
+ }) => theme.lineHeights[2]};
54
+ color: ${({
55
+ theme
56
+ }) => theme.colors['text/neutral/subtlest']};
57
+ margin-left: ${({
58
+ theme
59
+ }) => forcePixelValue(theme.space[2])};
60
+ }
61
+
62
+ &:last-child {
63
+ &::after {
64
+ content: none;
65
+ }
66
+ }
67
+ `;
68
+ var index = Object.assign(Breadcrumbs, {
69
+ Item: BreadcrumbsItem
70
+ });
71
+
72
+ export { index as default };
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { default as Breadcrumbs } from './core/Breadcrumbs/index.js';
1
2
  export { default as Button } from './core/Button/index.js';
2
3
  export { default as Chip } from './core/Chip/index.js';
3
4
  export { default as Dialog } from './core/Dialog/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -57,5 +57,5 @@
57
57
  "react-is": "^18.2.0",
58
58
  "styled-system": "^5.1.5"
59
59
  },
60
- "gitHead": "905ea6546094f215ab7392effb88e7c93cca6ab9"
60
+ "gitHead": "6ff713421bda642cb8b25320dd43e1e769c14cbd"
61
61
  }