@meduza/ui-kit-2 0.1.7 → 0.1.9
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/dist/Image/Image.types.d.ts +2 -2
- package/dist/MaterialNote/MaterialNote.stories.d.ts +2 -1
- package/dist/MaterialNote/MaterialNote.types.d.ts +2 -1
- package/dist/MaterialTitle/MaterialTitle.types.d.ts +2 -2
- package/dist/Popover/Popover.types.d.ts +2 -2
- package/dist/Tag/Tag.types.d.ts +2 -2
- package/dist/ui-kit-2.cjs.development.js +83 -79
- package/dist/ui-kit-2.cjs.development.js.map +1 -1
- package/dist/ui-kit-2.cjs.production.min.js +1 -1
- package/dist/ui-kit-2.cjs.production.min.js.map +1 -1
- package/dist/ui-kit-2.esm.js +83 -79
- package/dist/ui-kit-2.esm.js.map +1 -1
- package/dist/ui-kit.css +446 -446
- package/dist/utils/DangerousHtml.d.ts +3 -3
- package/dist/utils/makeClassName.d.ts +2 -1
- package/dist/utils/makeStyleContext.d.ts +2 -1
- package/package.json +12 -4
- package/src/BookmarkButton/BookmarkButton.stories.tsx +1 -1
- package/src/BookmarkButton/index.tsx +2 -4
- package/src/Button/Button.stories.tsx +2 -2
- package/src/Button/Button.test.tsx +3 -3
- package/src/Button/index.tsx +3 -3
- package/src/CardTitle/CardTitle.stories.tsx +1 -1
- package/src/CardTitle/CardTitle.test.tsx +1 -1
- package/src/CardTitle/index.tsx +1 -2
- package/src/ChapterBlock/ChapterBlock.stories.tsx +1 -1
- package/src/ChapterBlock/ChapterBlock.test.tsx +1 -1
- package/src/ChapterBlock/index.tsx +4 -8
- package/src/Cover/Cover.stories.tsx +1 -1
- package/src/Cover/Cover.test.tsx +1 -1
- package/src/Cover/index.tsx +5 -6
- package/src/DocumentItemsCount/DocumentItemsCount.stories.tsx +2 -2
- package/src/DocumentItemsCount/DocumentItemsCount.test.tsx +1 -1
- package/src/DocumentItemsCount/index.tsx +0 -1
- package/src/DotsOnImage/DotsOnImage.stories.tsx +1 -1
- package/src/DotsOnImage/DotsOnImage.test.tsx +1 -0
- package/src/DotsOnImage/index.tsx +1 -2
- package/src/Dropdown/index.tsx +2 -2
- package/src/EmbedBlock/EmbedBlock.stories.tsx +2 -2
- package/src/EmbedBlock/EmbedBlock.test.tsx +1 -1
- package/src/EmbedBlock/EmbedBlock.tsx +3 -8
- package/src/EmbedBlock/EmbedGif.tsx +0 -3
- package/src/EmbedBlock/IframeBlock.tsx +0 -1
- package/src/EmbedBlock/index.tsx +0 -1
- package/src/GroupedBlock/GroupedBlock.stories.tsx +2 -2
- package/src/GroupedBlock/GroupedBlock.test.tsx +1 -1
- package/src/GroupedBlock/GroupedBlock.types.ts +1 -1
- package/src/GroupedBlock/index.tsx +4 -6
- package/src/HalfBlock/HalfBlock.stories.tsx +1 -1
- package/src/HalfBlock/HalfBlock.test.tsx +1 -1
- package/src/HalfBlock/HalfBlock.types.ts +1 -1
- package/src/HalfBlock/index.tsx +3 -5
- package/src/Image/Image.stories.tsx +1 -1
- package/src/Image/Image.test.tsx +1 -1
- package/src/Image/Image.types.ts +2 -2
- package/src/Image/RenderPicture.tsx +1 -2
- package/src/Image/index.tsx +1 -6
- package/src/ImportantLead/ImportantLead.stories.tsx +1 -1
- package/src/ImportantLead/ImportantLead.test.tsx +1 -1
- package/src/ImportantLead/index.tsx +3 -5
- package/src/Lazy/Lazy.stories.tsx +3 -2
- package/src/Lazy/Lazy.test.tsx +1 -1
- package/src/Lazy/index.tsx +2 -4
- package/src/ListBlock/ListBlock.stories.tsx +3 -3
- package/src/ListBlock/ListBlock.test.tsx +1 -1
- package/src/ListBlock/index.tsx +3 -5
- package/src/MaterialNote/MaterialNote.stories.tsx +4 -3
- package/src/MaterialNote/MaterialNote.test.tsx +1 -1
- package/src/MaterialNote/MaterialNote.types.ts +2 -1
- package/src/MaterialNote/index.tsx +3 -3
- package/src/MaterialTitle/MaterialTitle.stories.tsx +1 -1
- package/src/MaterialTitle/MaterialTitle.test.tsx +1 -1
- package/src/MaterialTitle/MaterialTitle.types.ts +2 -1
- package/src/MediaCaption/MediaCaption.stories.tsx +1 -1
- package/src/MediaCaption/MediaCaption.test.tsx +1 -1
- package/src/MediaCaption/MediaCaption.types.ts +2 -2
- package/src/MediaCaption/index.tsx +2 -2
- package/src/Meta/Meta.stories.tsx +2 -2
- package/src/Meta/Meta.test.tsx +1 -1
- package/src/Meta/MetaContainer.tsx +2 -4
- package/src/Meta/index.tsx +2 -3
- package/src/MetaItem/MetaItem.stories.tsx +2 -2
- package/src/MetaItem/MetaItem.test.tsx +1 -1
- package/src/MetaItem/index.tsx +1 -3
- package/src/MetaItemLive/MetaItemLive.stories.tsx +2 -2
- package/src/MetaItemLive/MetaItemLive.test.tsx +1 -1
- package/src/MetaItemLive/index.tsx +1 -3
- package/src/Popover/Popover.stories.tsx +1 -1
- package/src/Popover/Popover.test.tsx +1 -1
- package/src/Popover/Popover.types.ts +2 -1
- package/src/Popover/index.tsx +1 -2
- package/src/QuoteBlock/QuoteBlock.stories.tsx +1 -1
- package/src/QuoteBlock/QuoteBlock.test.tsx +1 -1
- package/src/QuoteBlock/index.tsx +2 -3
- package/src/RawHtmlBlock/RawHtmlBlock.stories.tsx +2 -2
- package/src/RawHtmlBlock/RawHtmlBlock.test.tsx +1 -1
- package/src/RawHtmlBlock/index.tsx +0 -2
- package/src/RelatedBlock/RelatedBlock.stories.tsx +1 -1
- package/src/RelatedBlock/RelatedBlock.test.tsx +1 -1
- package/src/RelatedBlock/index.tsx +2 -3
- package/src/RenderBlocks/RenderBlocks.stories.tsx +1 -1
- package/src/RenderBlocks/RenderBlocks.test.tsx +1 -1
- package/src/RenderBlocks/index.tsx +0 -1
- package/src/RichTitle/RichTitle.stories.tsx +1 -1
- package/src/RichTitle/RichTitle.test.tsx +1 -1
- package/src/RichTitle/index.tsx +2 -3
- package/src/SimpleBlock/SimpleBlock.stories.tsx +2 -2
- package/src/SimpleBlock/SimpleBlock.test.tsx +1 -1
- package/src/SimpleBlock/index.tsx +8 -11
- package/src/SimpleTitle/SimpleTitle.stories.tsx +1 -1
- package/src/SimpleTitle/SimpleTitle.test.tsx +1 -1
- package/src/SimpleTitle/index.tsx +2 -2
- package/src/SourceBlock/SourceBlock.stories.tsx +6 -6
- package/src/SourceBlock/SourceBlock.test.tsx +1 -1
- package/src/SourceBlock/index.tsx +7 -6
- package/src/SourceBlock/mock.json +15 -0
- package/src/Spoiler/Spoiler.stories.tsx +1 -1
- package/src/Spoiler/Spoiler.test.tsx +1 -1
- package/src/Spoiler/index.tsx +4 -5
- package/src/SvgSymbol/SvgSymbol.stories.tsx +6 -6
- package/src/SvgSymbol/SvgSymbol.test.tsx +1 -1
- package/src/SvgSymbol/index.tsx +2 -2
- package/src/Switcher/Switcher.stories.tsx +4 -4
- package/src/Switcher/Switcher.test.tsx +1 -1
- package/src/Switcher/index.tsx +1 -2
- package/src/Table/Table.stories.tsx +1 -1
- package/src/Table/Table.test.tsx +1 -1
- package/src/Table/index.tsx +2 -2
- package/src/Tag/Tag.stories.tsx +1 -3
- package/src/Tag/Tag.test.tsx +4 -4
- package/src/Tag/Tag.types.ts +3 -1
- package/src/Tag/index.tsx +2 -2
- package/src/Timestamp/Timestamp.stories.tsx +1 -1
- package/src/Timestamp/Timestamp.test.tsx +1 -1
- package/src/Timestamp/index.tsx +0 -2
- package/src/Toolbar/Toolbar.stories.tsx +0 -2
- package/src/Toolbar/Toolbar.test.tsx +1 -1
- package/src/Toolbar/index.tsx +2 -3
- package/src/ToolbarButton/ToolbarButton.stories.tsx +2 -2
- package/src/ToolbarButton/ToolbarButton.test.tsx +1 -1
- package/src/ToolbarButton/index.tsx +2 -3
- package/src/_storybook/PreviewWrapper/index.tsx +1 -1
- package/src/utils/DangerousHtml.tsx +26 -18
- package/src/utils/generateGradient.ts +1 -1
- package/src/utils/makeClassName.ts +3 -1
- package/src/utils/makeStyleContext.ts +8 -4
- package/src/utils/toCamel.ts +1 -1
package/src/Toolbar/index.tsx
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React, { Children } from 'react'
|
|
2
2
|
import { ToolbarProps } from './Toolbar.types'
|
|
3
|
-
|
|
4
3
|
import makeStyleContext from '../utils/makeStyleContext'
|
|
5
|
-
import makeClassName from '../utils/makeClassName'
|
|
4
|
+
import { makeClassName, ClassNames } from '../utils/makeClassName'
|
|
6
5
|
|
|
7
6
|
import styles from './Toolbar.module.css'
|
|
8
7
|
|
|
9
8
|
export const Toolbar: React.FC<ToolbarProps> = ({ children, styleContext }) => {
|
|
10
|
-
let classNames:
|
|
9
|
+
let classNames: ClassNames = [[styles.root, true]]
|
|
11
10
|
|
|
12
11
|
if (styleContext) {
|
|
13
12
|
classNames = makeStyleContext(classNames, styleContext, styles)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
|
|
3
2
|
import { ToolbarButton } from './'
|
|
4
|
-
import { PreviewWrapper } from '_storybook/PreviewWrapper'
|
|
3
|
+
import { PreviewWrapper } from '../_storybook/PreviewWrapper'
|
|
4
|
+
|
|
5
5
|
import styles from './ToolbarButton.stories.module.css'
|
|
6
6
|
|
|
7
7
|
export default {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react'
|
|
3
|
-
|
|
4
3
|
import { ToolbarButton } from './'
|
|
5
4
|
import { ToolbarButtonProps } from './ToolbarButton.types'
|
|
5
|
+
|
|
6
6
|
import styles from './ToolbarButton.module.css'
|
|
7
7
|
|
|
8
8
|
describe('Toolbar Button', () => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { ToolbarButtonProps } from './ToolbarButton.types'
|
|
3
|
-
|
|
4
3
|
import { SvgSymbol } from '../SvgSymbol/'
|
|
5
|
-
import makeClassName from '../utils/makeClassName'
|
|
4
|
+
import { makeClassName, ClassNames } from '../utils/makeClassName'
|
|
6
5
|
|
|
7
6
|
import styles from './ToolbarButton.module.css'
|
|
8
7
|
|
|
@@ -13,7 +12,7 @@ export const ToolbarButton: React.FC<ToolbarButtonProps> = ({
|
|
|
13
12
|
isActive,
|
|
14
13
|
onClick
|
|
15
14
|
}) => {
|
|
16
|
-
const classNames:
|
|
15
|
+
const classNames: ClassNames = [
|
|
17
16
|
[styles.root, true],
|
|
18
17
|
[styles[type], !!styles[type]],
|
|
19
18
|
[styles[theme], !!styles[theme] && !!theme],
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type DangerousHtmlProps = {
|
|
4
4
|
className?: string
|
|
5
5
|
html: string
|
|
6
|
-
tagName?:
|
|
6
|
+
tagName?: keyof JSX.IntrinsicElements
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const DangerousHTML: React.FC<DangerousHtmlProps> = ({
|
|
@@ -11,23 +11,21 @@ const DangerousHTML: React.FC<DangerousHtmlProps> = ({
|
|
|
11
11
|
tagName: TagName = 'div',
|
|
12
12
|
html
|
|
13
13
|
}) => {
|
|
14
|
-
const element = useRef<
|
|
14
|
+
const element = useRef<HTMLDivElement>(null)
|
|
15
15
|
const [canRenderHtml, setCanRenderHtml] = useState(false)
|
|
16
16
|
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
setCanRenderHtml(true)
|
|
19
19
|
}, [])
|
|
20
20
|
|
|
21
|
-
const replaceScriptElementsRecursive = useCallback(node => {
|
|
21
|
+
const replaceScriptElementsRecursive = useCallback((node) => {
|
|
22
22
|
if (
|
|
23
23
|
node.tagName === 'SCRIPT' &&
|
|
24
24
|
(!node.id || node.id.indexOf('script-') !== 0)
|
|
25
25
|
) {
|
|
26
26
|
const script = document.createElement('script')
|
|
27
27
|
|
|
28
|
-
script.id = `script-${Math.random()
|
|
29
|
-
.toString(16)
|
|
30
|
-
.slice(2)}`
|
|
28
|
+
script.id = `script-${Math.random().toString(16).slice(2)}`
|
|
31
29
|
script.innerHTML = node.innerHTML
|
|
32
30
|
|
|
33
31
|
const attrs = node.attributes
|
|
@@ -53,26 +51,36 @@ const DangerousHTML: React.FC<DangerousHtmlProps> = ({
|
|
|
53
51
|
const prepareAnchors = useCallback(() => {
|
|
54
52
|
const anchors = Array.from(element.current.querySelectorAll('a'))
|
|
55
53
|
|
|
56
|
-
anchors.forEach(a => {
|
|
54
|
+
anchors.forEach((a) => {
|
|
57
55
|
a.setAttribute('target', '_blank')
|
|
58
56
|
})
|
|
59
57
|
}, [])
|
|
60
58
|
|
|
61
59
|
useEffect(() => {
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (
|
|
61
|
+
canRenderHtml &&
|
|
62
|
+
html.indexOf('script') > -1 &&
|
|
63
|
+
element.current.firstElementChild
|
|
64
|
+
) {
|
|
65
|
+
element.current.firstElementChild.innerHTML = html
|
|
66
|
+
replaceScriptElementsRecursive(element.current.firstElementChild)
|
|
65
67
|
prepareAnchors()
|
|
66
68
|
}
|
|
67
|
-
}, [
|
|
69
|
+
}, [
|
|
70
|
+
canRenderHtml,
|
|
71
|
+
element,
|
|
72
|
+
html,
|
|
73
|
+
replaceScriptElementsRecursive,
|
|
74
|
+
prepareAnchors
|
|
75
|
+
])
|
|
68
76
|
|
|
69
77
|
return (
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
<div ref={element}>
|
|
79
|
+
<TagName
|
|
80
|
+
className={className}
|
|
81
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
76
84
|
)
|
|
77
85
|
}
|
|
78
86
|
|
|
@@ -13,7 +13,7 @@ const generateGradient = (color: string): string => {
|
|
|
13
13
|
[1, 82]
|
|
14
14
|
]
|
|
15
15
|
|
|
16
|
-
const gradient = gradientSteps.map(i => `rgba(${color}, ${i[0]}) ${i[1]}%`)
|
|
16
|
+
const gradient = gradientSteps.map((i) => `rgba(${color}, ${i[0]}) ${i[1]}%`)
|
|
17
17
|
|
|
18
18
|
return `linear-gradient(-180deg, ${gradient})`
|
|
19
19
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export type ClassNames = (string[] | string | boolean)[][]
|
|
2
|
+
|
|
3
|
+
export const makeClassName = (list: ClassNames): string => {
|
|
2
4
|
return list
|
|
3
5
|
.filter(([, active]) => active)
|
|
4
6
|
.map(([className]) => className)
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { ClassNames } from './makeClassName'
|
|
2
|
+
|
|
1
3
|
const makeStyleContext = (
|
|
2
|
-
classNames:
|
|
4
|
+
classNames: ClassNames,
|
|
3
5
|
styleContext: string[] | string,
|
|
4
|
-
styles
|
|
5
|
-
):
|
|
6
|
+
styles: Record<string, string>
|
|
7
|
+
): ClassNames => {
|
|
6
8
|
const context = Array.isArray(styleContext)
|
|
7
|
-
? styleContext
|
|
9
|
+
? styleContext
|
|
10
|
+
.filter((ctx) => styles[ctx])
|
|
11
|
+
.map((ctx) => [[styles[ctx]], true])
|
|
8
12
|
: [[styles[styleContext], !!styleContext && !!styles[styleContext]]]
|
|
9
13
|
|
|
10
14
|
return classNames.concat(context)
|
package/src/utils/toCamel.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const toCamel = (s: string): string =>
|
|
2
|
-
s.replace(/([_][a-z])/gi, str => str.toUpperCase().replace('_', ''))
|
|
2
|
+
s.replace(/([_][a-z])/gi, (str) => str.toUpperCase().replace('_', ''))
|