diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md new file mode 100644 index 000000000..5221472eb --- /dev/null +++ b/CONTRIBUTION.md @@ -0,0 +1,38 @@ +# Contribution + +## Running project locally + +### ReactTooltip (root) + +1. Run `npm install` || `yarn` to install dependencies +2. You can test by: `yarn dev` to run dev mode, or you can run **docs** directly using root folder instead of NPM, for this, please check **docs section**. + +### Docs + +You still need step 1 from `ReactTooltip (root)` section. +Docs are commited using npm packages, but with this steps, you can use local ReactTooltip package build. + +1. In **docs** folder, run `npm install` || `yarn` to install dependencies +2. In **root** folder (parent of docs folder), run `yarn build` to generate a production build (you can use `yarn build --watch` to always generate a new build when a file changes) +3. Change `package.json`: + +From this: +``` +"react": "18.2.0", +"react-dom": "18.2.0", +"react-tooltip": "5.0.0" +``` + +To this: +``` +"react": "link:../node_modules/react", +"react-dom": "link:../node_modules/react-dom", +"react-tooltip": "link:.." + +``` + +4. Run `yarn start` and open `localhost:3000` to see docs running locally. + +OBS: do not commit this change or the docs will broken the deployment and will not be updated. + + diff --git a/README.md b/README.md index 55413b58f..8f1647b0d 100755 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ import ReactDOMServer from 'react-dom/server'; [danielbarion](https://github.com/danielbarion) Maintainer - Creator of React Tooltip >= V5. +[gabrieljablonski](https://github.com/gabrieljablonski) Maintainer. + [aronhelser](https://github.com/aronhelser) Passive maintainer - accepting PRs and doing minor testing, but not fixing issues or doing active development. [alexgurr](https://github.com/alexgurr) (inactive). diff --git a/docs/docs/examples/_category_.json b/docs/docs/examples/_category_.json index 7170e1ebc..9d1e296b3 100644 --- a/docs/docs/examples/_category_.json +++ b/docs/docs/examples/_category_.json @@ -2,6 +2,7 @@ "label": "Examples", "position": 4, "link": { - "type": "generated-index" + "type": "generated-index", + "description": "Examples using props and some use cases with ReactTooltip component" } } diff --git a/docs/docs/examples/styling.mdx b/docs/docs/examples/styling.mdx index eb09701c7..24a6b060c 100644 --- a/docs/docs/examples/styling.mdx +++ b/docs/docs/examples/styling.mdx @@ -6,8 +6,12 @@ sidebar_position: 1 How to customize tooltip styles in ReactTooltip styles. +Now tooltip arrow inherit his background color from tooltip (his parent). + import { Tooltip } from 'react-tooltip' import 'react-tooltip/dist/react-tooltip.css' +import CodeBlock from '@theme/CodeBlock' +import TooltipStyles from '!!raw-loader!../../../src/components/Tooltip/styles.module.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -33,31 +37,55 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { ) } -### Basic explanation +### Basic explanation - Inline Styling + +You can add styles into the tooltip as inline styling. + +```jsx +import { Tooltip } from 'react-tooltip' +import 'react-tooltip/dist/react-tooltip.css' + + + ◕‿‿◕ + + +``` + +
+ + ◕‿‿◕ + + +
+ + +### Basic explanation - Classes You don't need `!important` anymore, you just need to know at least a bit about CSS Specificity ([MDN Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) | [W3c Docs](https://www.w3schools.com/css/css_specificity.asp)). Using CSS Specificity you can add a class with more specificity than the current used in tooltip and you can override or add new rules to the component style. + ```jsx import { Tooltip } from 'react-tooltip' import 'react-tooltip/dist/react-tooltip.css'
◕‿‿◕ - +
``` @@ -68,74 +96,14 @@ import 'react-tooltip/dist/react-tooltip.css' ◕‿‿◕ - + #### Explanation In this example, we are adding an extra level to the CSS classes, the following styles are the default one of Tooltip component when we write this docs: -```css -.tooltip { - visibility: hidden; - width: max-content; - position: absolute; - top: 0; - left: 0; - padding: 8px 16px; - border-radius: 3px; - font-size: 90%; - pointer-events: none; - opacity: 0; - transition: opacity 0.3s ease-out; - will-change: opacity, visibility; -} - -.arrow { - position: absolute; - background: var(--rt-color-dark); - width: 8px; - height: 8px; - transform: rotate(45deg); -} - -/** Types variant **/ -.dark, -.dark .arrow { - background: var(--rt-color-dark); - color: var(--rt-color-white); -} - -.light, -.light .arrow { - background-color: var(--rt-color-white); - color: var(--rt-color-dark); -} - -.success, -.success .arrow { - background-color: var(--rt-color-success); - color: var(--rt-color-white); -} - -.warning, -.warning .arrow { - background-color: var(--rt-color-warning); - color: var(--rt-color-white); -} - -.error, -.error .arrow { - background-color: var(--rt-color-error); - color: var(--rt-color-white); -} - -.info, -.info .arrow { - background-color: var(--rt-color-info); - color: var(--rt-color-white); -} -``` +{TooltipStyles} So, if we only add new classes like the below, this will not work because this is the same level of specificity than the default dark variant as example, you can compare: @@ -145,20 +113,9 @@ So, if we only add new classes like the below, this will not work because this i background-color: rgb(0, 247, 255); } +/** add next line only if you want to have tooltip arrow with a different background color from tooltip **/ .example .example-arrow { - background-color: rgb(0, 247, 255); -} -``` - -```css -.tooltip { - ...; -} - -.dark, -.dark .arrow { - background: var(--rt-color-dark); - color: var(--rt-color-white); + background-color: rgb(255, 0, 0); } ``` @@ -170,8 +127,9 @@ So, to make this work as expected, we need to add a new more level like this one background-color: rgb(0, 247, 255); } +/** add next line only if you want to have tooltip arrow with a different background color from tooltip **/ .some-class-or-rule .example .example-arrow { - background-color: rgb(0, 247, 255); + background-color: rgb(255, 0, 0); } ``` @@ -192,17 +150,13 @@ import 'react-tooltip/dist/react-tooltip.css' color: #222; background-color: rgb(255, 153, 0); } - -.example-container .example-orange .example-arrow { - background-color: rgb(255, 153, 0); -}
◕‿‿◕ - +
``` @@ -216,7 +170,6 @@ import 'react-tooltip/dist/react-tooltip.css' @@ -231,17 +184,13 @@ import 'react-tooltip/dist/react-tooltip.css' color: #fff; background-color: rgb(255, 0, 255); } - -.example-container .example-pink .example-arrow { - background-color: rgb(255, 0, 255); -}
◕‿‿◕ - +
``` @@ -252,7 +201,42 @@ import 'react-tooltip/dist/react-tooltip.css' ◕‿‿◕ - + + + +#### Tooltip Arrow with a different color from Tooltip + +```jsx +import { Tooltip } from 'react-tooltip' +import 'react-tooltip/dist/react-tooltip.css' + + + + +``` + +
+ + ◕‿‿◕ + +
### More examples - Radius diff --git a/docs/docs/getting-started.mdx b/docs/docs/getting-started.mdx index 1786b5072..d759d7ec5 100644 --- a/docs/docs/getting-started.mdx +++ b/docs/docs/getting-started.mdx @@ -85,11 +85,15 @@ import ReactTooltip from 'react-tooltip' 2 . Add data-content = "your placeholder" to your element ```jsx -

+

Tooltip

``` +### Styling + +If you want a styled tooltip, don't forget to add the style file `import 'react-tooltip/dist/react-tooltip.css` + 3 . Include react-tooltip component ```jsx diff --git a/docs/docs/options.mdx b/docs/docs/options.mdx index 2bd54d5b4..49f706a03 100644 --- a/docs/docs/options.mdx +++ b/docs/docs/options.mdx @@ -66,6 +66,7 @@ import 'react-tooltip/dist/react-tooltip.css' | positionStrategy | string | false | `absolute` | `absolute` `fixed` | the position strategy used for the tooltip. set to `fixed` if you run into issues with `overflow: hidden` on the tooltip parent container | | delayShow | number | false | | any `number` | tooltip show will be delayed in miliseconds by the amount of value | | delayHide | number | false | | any `number` | tooltip hide will be delayed in miliseconds by the amount of value | +| style | CSSProperties | false | | any React inline style | add styles directly to the component by `style` attribute | | getContent | function | false | | (value: string) => string | a method available to parse, format or modify the given content of tooltip before show it | | isOpen | boolen | false | handled by internal state | `true` `false` | the tooltip can be controlled or uncontrolled, this attribute can be used to handle show and hide tooltip outside tooltip (can be used **without** `setIsOpen`) | | setIsOpen | function | false | | | the tooltip can be controlled or uncontrolled, this attribute can be used to handle show and hide tooltip outside tooltip | diff --git a/docs/docs/upgrade-guide/_category_.json b/docs/docs/upgrade-guide/_category_.json index b34f76e4a..daae91973 100644 --- a/docs/docs/upgrade-guide/_category_.json +++ b/docs/docs/upgrade-guide/_category_.json @@ -2,6 +2,7 @@ "label": "Upgrade Guide", "position": 2, "link": { - "type": "generated-index" + "type": "generated-index", + "description": "Upgrade docs related to migration from V4 to V5" } } diff --git a/docs/docs/upgrade-guide/basic-examples-v4-v5.mdx b/docs/docs/upgrade-guide/basic-examples-v4-v5.mdx index 106f469b1..aa530aab0 100644 --- a/docs/docs/upgrade-guide/basic-examples-v4-v5.mdx +++ b/docs/docs/upgrade-guide/basic-examples-v4-v5.mdx @@ -4,6 +4,8 @@ sidebar_position: 4 # Basic examples V4 -> V5 +Examples of use in V4 -> V5 + import { Tooltip } from 'react-tooltip' import 'react-tooltip/dist/react-tooltip.css' @@ -78,7 +80,7 @@ import 'react-tooltip/dist/react-tooltip.css'; --- -# Colors +## Colors ### V4 or less - type diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 51c97a803..fc8610c66 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -38,14 +38,14 @@ const config = { sidebarPath: require.resolve('./sidebars.js'), // Please change this to your repo. // Remove this to remove the "edit this page" links. - editUrl: 'https://github.com/ReactTooltip/react-tooltip/tree/v5/docs/', + editUrl: 'https://github.com/ReactTooltip/react-tooltip/tree/master/docs/', }, // blog: { // showReadingTime: true, // // Please change this to your repo. // // Remove this to remove the "edit this page" links. // editUrl: - // 'https://github.com/ReactTooltip/react-tooltip/tree/v5/docs/', + // 'https://github.com/ReactTooltip/react-tooltip/tree/master/docs/', // }, theme: { customCss: require.resolve('./src/css/custom.css'), diff --git a/docs/package.json b/docs/package.json index de90c1441..98b9615c6 100644 --- a/docs/package.json +++ b/docs/package.json @@ -20,6 +20,7 @@ "@mdx-js/react": "^1.6.22", "clsx": "^1.2.1", "prism-react-renderer": "^1.3.5", + "raw-loader": "^4.0.2", "react": "18.2.0", "react-dom": "18.2.0", "react-tooltip": "5.0.0" diff --git a/docs/src/css/custom.css b/docs/src/css/custom.css index 071be2f33..75c8aae3a 100644 --- a/docs/src/css/custom.css +++ b/docs/src/css/custom.css @@ -35,26 +35,23 @@ background-color: rgb(0, 247, 255); } -.example-container .example .example-arrow { - background-color: rgb(0, 247, 255); -} - .example-container .example-orange { color: #222; background-color: rgb(255, 153, 0); } -.example-container .example-orange .example-arrow { - background-color: rgb(255, 153, 0); -} - .example-container .example-pink { color: #fff; background-color: rgb(255, 0, 255); } -.example-container .example-pink .example-arrow { - background-color: rgb(255, 0, 255); +.example-container .example-diff-arrow { + color: #fff; + background-color: rgb(55, 55, 55); +} + +.example-container .example-diff-arrow .example-arrow { + background-color: rgb(222, 34, 72); } .example-container .example-no-radius { diff --git a/docs/static/robots.txt b/docs/static/robots.txt new file mode 100644 index 000000000..8a6c4e1f7 --- /dev/null +++ b/docs/static/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://react-tooltip.com/sitemap.xml diff --git a/docs/yarn.lock b/docs/yarn.lock index 4fdca97ff..76b076c30 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -5954,6 +5954,14 @@ raw-body@2.5.1: iconv-lite "0.4.24" unpipe "1.0.0" +raw-loader@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-4.0.2.tgz#1aac6b7d1ad1501e66efdac1522c73e59a584eb6" + integrity sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA== + dependencies: + loader-utils "^2.0.0" + schema-utils "^3.0.0" + rc@1.2.8, rc@^1.2.8: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" diff --git a/package.json b/package.json index 2f4e5fea3..4b1b8d3e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-tooltip", - "version": "5.0.0", + "version": "5.1.0", "description": "react tooltip component", "scripts": { "dev": "node ./cli.js --env=development && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.dev.js --watch", @@ -85,7 +85,7 @@ "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-browsersync": "^1.3.3", "rollup-plugin-copy": "^3.4.0", - "rollup-plugin-dts": "4.2.3", + "rollup-plugin-dts": "^5.0.0", "rollup-plugin-filesize": "^9.1.1", "rollup-plugin-html-scaffold": "^0.2.0", "rollup-plugin-postcss": "^4.0.1", diff --git a/rollup.config.types.js b/rollup.config.types.js index b28ee6400..10dab8dc2 100644 --- a/rollup.config.types.js +++ b/rollup.config.types.js @@ -6,12 +6,16 @@ export default { output: [{ file: 'dist/react-tooltip.d.ts', format: 'es' }], plugins: [ postcss({ - extract: 'react-tooltip-tokens.css', // this will generate a specific file and override on multiples build, but the css will be the same + extract: 'react-tooltip-tokens.css', // this will generate a specific file not being used, but we need this part of code autoModules: true, include: '**/*.css', extensions: ['.css'], plugins: [], }), - dts(), + dts({ + compilerOptions: { + baseUrl: 'src', + }, + }), ], } diff --git a/src/App.tsx b/src/App.tsx index 25c338d41..d155271c1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -40,6 +40,15 @@ function App() { isOpen={isDarkOpen} setIsOpen={setIsDarkOpen} /> +

diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 64ba07744..17e1d0061 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -21,6 +21,7 @@ const Tooltip = ({ children = null, delayShow = 0, delayHide = 0, + style: externalStyles, // props handled by controller isHtmlContent = false, content, @@ -174,7 +175,7 @@ const Tooltip = ({ [styles['show']]: isOpen || show, [styles['fixed']]: positionStrategy === 'fixed', })} - style={inlineStyles} + style={{ ...externalStyles, ...inlineStyles }} ref={tooltipRef as React.RefObject} > {children || (isHtmlContent ? : content)} diff --git a/src/components/Tooltip/TooltipTypes.d.ts b/src/components/Tooltip/TooltipTypes.d.ts index 73df7538d..ead6b5a7f 100644 --- a/src/components/Tooltip/TooltipTypes.d.ts +++ b/src/components/Tooltip/TooltipTypes.d.ts @@ -1,4 +1,4 @@ -import type { ElementType, ReactNode, Element } from 'react' +import type { ElementType, ReactNode, Element, CSSProperties } from 'react' export type PlacesType = 'top' | 'right' | 'bottom' | 'left' @@ -29,6 +29,7 @@ export interface ITooltip { positionStrategy?: PositionStrategy delayShow?: number delayHide?: number + style?: CSSProperties isOpen?: boolean setIsOpen?: (value: boolean) => void } diff --git a/src/components/Tooltip/styles.module.css b/src/components/Tooltip/styles.module.css index 29833fa30..d2ad7c29c 100644 --- a/src/components/Tooltip/styles.module.css +++ b/src/components/Tooltip/styles.module.css @@ -19,7 +19,7 @@ .arrow { position: absolute; - background: var(--rt-color-dark); + background: inherit; width: 8px; height: 8px; transform: rotate(45deg); @@ -31,38 +31,32 @@ } /** Types variant **/ -.dark, -.dark .arrow { +.dark { background: var(--rt-color-dark); color: var(--rt-color-white); } -.light, -.light .arrow { +.light { background-color: var(--rt-color-white); color: var(--rt-color-dark); } -.success, -.success .arrow { +.success { background-color: var(--rt-color-success); color: var(--rt-color-white); } -.warning, -.warning .arrow { +.warning { background-color: var(--rt-color-warning); color: var(--rt-color-white); } -.error, -.error .arrow { +.error { background-color: var(--rt-color-error); color: var(--rt-color-white); } -.info, -.info .arrow { +.info { background-color: var(--rt-color-info); color: var(--rt-color-white); } diff --git a/src/components/TooltipController/TooltipController.tsx b/src/components/TooltipController/TooltipController.tsx index 15ea6366b..695bbd30d 100644 --- a/src/components/TooltipController/TooltipController.tsx +++ b/src/components/TooltipController/TooltipController.tsx @@ -26,6 +26,7 @@ const TooltipController = ({ positionStrategy = 'absolute', delayShow = 0, delayHide = 0, + style, getContent, isOpen, setIsOpen, @@ -191,6 +192,7 @@ const TooltipController = ({ positionStrategy: tooltipPositionStrategy, delayShow: tooltipDelayShow, delayHide: tooltipDelayHide, + style, isOpen, setIsOpen, } diff --git a/src/components/TooltipController/TooltipControllerTypes.d.ts b/src/components/TooltipController/TooltipControllerTypes.d.ts index 2537575e4..4b3ade313 100644 --- a/src/components/TooltipController/TooltipControllerTypes.d.ts +++ b/src/components/TooltipController/TooltipControllerTypes.d.ts @@ -1,3 +1,5 @@ +import type { CSSProperties } from 'react' + import type { PlacesType, VariantType, @@ -23,7 +25,8 @@ export interface ITooltipController { positionStrategy?: PositionStrategy delayShow?: number delayHide?: number - getContent?: function + getContent?: (value) => string + style?: CSSProperties isOpen?: boolean setIsOpen?: (value: boolean) => void } diff --git a/yarn.lock b/yarn.lock index 5351cf78d..f031aa86d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5214,7 +5214,7 @@ magic-string@^0.25.7: dependencies: sourcemap-codec "^1.4.8" -magic-string@^0.26.6: +magic-string@^0.26.7: version "0.26.7" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.7.tgz#caf7daf61b34e9982f8228c4527474dac8981d6f" integrity sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow== @@ -6856,12 +6856,12 @@ rollup-plugin-copy@^3.4.0: globby "10.0.1" is-plain-object "^3.0.0" -rollup-plugin-dts@4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-4.2.3.tgz#04c3615df1ffab4228aa9d540697eaca61e01f47" - integrity sha512-jlcpItqM2efqfIiKzDB/IKOS9E9fDvbkJSGw5GtK/PqPGS9eC3R3JKyw2VvpTktZA+TNgJRMu1NTv244aTUzzQ== +rollup-plugin-dts@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-5.0.0.tgz#d645f222ea6f7d6b7ddb7ea98c45a0e5a3a569ec" + integrity sha512-OO8ayCvuJCKaQSShyVTARxGurVVk4ulzbuvz+0zFd1f93vlnWFU5pBMT7HFeS6uj7MvvZLx4kUAarGATSU1+Ng== dependencies: - magic-string "^0.26.6" + magic-string "^0.26.7" optionalDependencies: "@babel/code-frame" "^7.18.6"