Skip to content

Commit

Permalink
Implemented the customization of styles of the Tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
dkvovik committed Mar 29, 2024
1 parent 90e69c2 commit 2acfafb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/drawing-toolbar/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/drawing-toolbar/src/components/line-settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const lineSizes = {
EIGHT: 8,
}


export const LineSettings = ({
currentSize, handleClick, dashed = false,
}) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/tooltip/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/tooltip/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/tooltip",
"version": "1.0.0",
"version": "1.0.1-dev-0-ULMS-2928",
"description": "",
"keywords": [
"lerna"
Expand Down
16 changes: 15 additions & 1 deletion packages/tooltip/src/tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { memo, useMemo } from 'react'
import styled from 'styled-components'
import { Tooltip as TooltipComponent } from '@foxford/ui'

import { deepMerge } from './utils'

const styles = {
wrapper: {
height: '100%',
Expand All @@ -25,6 +27,8 @@ const styles = {
fontSize: '14px',
lineHeight: '130%',
color: '#333',
textAlign: 'center',
whiteSpace: 'pre-line',
},
arrow: {
spread: 16,
Expand Down Expand Up @@ -69,7 +73,17 @@ function _Tooltip ({
dark,
...tooltipProps
}) {
const computedStyles = useMemo(() => dark ? darkStyles : styles, [dark, customStyles])
const computedStyles = useMemo(
() => deepMerge(customStyles, dark ? darkStyles : styles),
[dark, customStyles]
)

// if (Object.keys(customStyles).length) {
// console.log('!!!', {
// computedStyles,
// customStyles,
// })
// }

return disabled || hideTooltip
? (
Expand Down
49 changes: 49 additions & 0 deletions packages/tooltip/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function deepCopy (obj) {
const result = {}

if (typeof obj !== 'object'
|| typeof obj === 'undefined'
|| obj === null
|| Array.isArray(obj)
|| typeof obj === 'function') {
return obj
}

const keys = Object.keys(obj)

// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const key in keys) {
result[keys[key]] = deepCopy(obj[keys[key]])
}

return result
}

export function deepMerge (value1, value2) {
const obj1 = deepCopy(value1)
const obj2 = deepCopy(value2)
const mergedObj = {}

// eslint-disable-next-line no-restricted-syntax
for (const key in obj1) {
if (typeof obj1[key] === 'object' && obj1[key] !== null) {
if (obj2[key] && typeof obj2[key] === 'object' && obj2[key] !== null) {
mergedObj[key] = deepMerge(obj1[key], obj2[key])
} else {
mergedObj[key] = obj1[key]
}
} else {
mergedObj[key] = obj1[key]
}
}

// eslint-disable-next-line no-restricted-syntax
for (const key in obj2) {
// eslint-disable-next-line no-prototype-builtins
if (obj2.hasOwnProperty(key) && !obj1.hasOwnProperty(key)) {
mergedObj[key] = obj2[key]
}
}

return mergedObj
}

0 comments on commit 2acfafb

Please sign in to comment.