Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V6 biome #1218

Draft
wants to merge 3 commits into
base: v6
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"include": ["./src"],
"ignore": ["node_modules/**", "dist/**", "build/**", "coverage/**", "public/**", "docs/**", "./src/App.tsx"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"useLiteralKeys": "off"
}
}
},
"javascript": {
"formatter": {
"semicolons": "asNeeded",
"lineWidth": 100,
"quoteStyle": "single",
"indentStyle": "space"
}
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"bundlesize": "bundlesize",
"esbuild": "esbuild",
"test": "jest",
"biome:lint": "biome lint --max-diagnostics 1000 --apply ./src",
"biome:format": "biome format --max-diagnostics 1000 --write ./src",
"biome:pre-commit": "npm run biome:lint && npm run biome:format",
"postbuild": "npm run types && npm run bundlesize",
"prepublishOnly": "npm run build"
},
Expand Down Expand Up @@ -49,6 +52,7 @@
},
"homepage": "https://github.com/ReactTooltip/react-tooltip#readme",
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-replace": "5.0.7",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.prod.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const config = allBuildFormats.map(
}),
]

if (specificPlugins && specificPlugins.length) {
if (specificPlugins?.length) {
plugins.push(...specificPlugins)
}

Expand Down
31 changes: 24 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import { TooltipController as Tooltip } from 'components/TooltipController'
import { IPosition, TooltipRefProps } from 'components/Tooltip/TooltipTypes.d'
import type { IPosition, TooltipRefProps } from 'components/Tooltip/TooltipTypes.d'
import React, { useEffect, useRef, useState } from 'react'
import { inline, offset } from '@floating-ui/dom'
import styles from './styles.module.css'
Expand Down Expand Up @@ -81,13 +81,15 @@ function App() {
<p>
<button
id="button2"
type="button"
data-tooltip-content="Hello World from a Tooltip 2"
onClick={handleButtonClick}
>
Hover or focus me
</button>
<button
id="button3"
type="button"
data-tooltip-content="Hello World from a Tooltip 3"
onClick={handleButtonClick}
>
Expand All @@ -97,11 +99,19 @@ function App() {
</section>
<section id="section-anchor-select" style={{ marginTop: '100px' }}>
<p>
<button data-tooltip-id="anchor-select" data-tooltip-content="this content is different">
<button
type="button"
data-tooltip-id="anchor-select"
data-tooltip-content="this content is different"
>
Anchor select
</button>
<button data-tooltip-id="anchor-select">Anchor select 2</button>
<button data-tooltip-id="anchor-select">Anchor select 3</button>
<button type="button" data-tooltip-id="anchor-select">
Anchor select 2
</button>
<button type="button" data-tooltip-id="anchor-select">
Anchor select 3
</button>
</p>
<Tooltip id="anchor-select">Tooltip content</Tooltip>
<Tooltip
Expand Down Expand Up @@ -163,6 +173,7 @@ function App() {
/>
</div>
<button
type="button"
id="imperativeTooltipButton"
style={{ height: 40, marginLeft: 100 }}
onClick={() => {
Expand All @@ -184,7 +195,9 @@ function App() {
</div>

<div style={{ marginTop: '1rem' }}>
<button id="buttonCallbacks">Check the dev console</button>
<button type="button" id="buttonCallbacks">
Check the dev console
</button>
<Tooltip
place="bottom"
anchorSelect="#buttonCallbacks"
Expand All @@ -195,7 +208,9 @@ function App() {
content="Showing tooltip and calling afterShow method"
/>

<button id="buttonCallbacksClick">With click event</button>
<button type="button" id="buttonCallbacksClick">
With click event
</button>
<Tooltip
openOnClick
place="bottom"
Expand All @@ -207,7 +222,9 @@ function App() {
content="Showing tooltip and calling afterShow method"
/>

<button id="buttonCallbacksDelay">With delay</button>
<button type="button" id="buttonCallbacksDelay">
With delay
</button>
<Tooltip
delayShow={1000}
place="bottom"
Expand Down
5 changes: 4 additions & 1 deletion src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,10 @@ const Tooltip = ({
window.addEventListener('click', handleClickOutsideAnchors)
}

const enabledEvents: { event: string; listener: (event?: Event) => void }[] = []
const enabledEvents: {
event: string
listener: (event?: Event) => void
}[] = []

const handleClickOpenTooltipAnchor = (event?: Event) => {
if (show && event?.target === activeAnchor) {
Expand Down
11 changes: 9 additions & 2 deletions src/components/TooltipController/TooltipController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(

// do not check for subtree and childrens, we only want to know attribute changes
// to stay watching `data-attributes-*` from anchor element
const observerConfig = { attributes: true, childList: false, subtree: false }
const observerConfig = {
attributes: true,
childList: false,
subtree: false,
}

if (activeAnchor) {
const dataAttributes = getDataAttributesFromAnchorElement(activeAnchor)
Expand Down Expand Up @@ -264,7 +268,10 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
if (render) {
const actualContent =
activeAnchor?.getAttribute('data-tooltip-content') || tooltipContent || null
const rendered = render({ content: actualContent, activeAnchor }) as React.ReactNode
const rendered = render({
content: actualContent,
activeAnchor,
}) as React.ReactNode
renderedContent = rendered ? (
<div ref={contentWrapperRef} className="react-tooltip-content-wrapper">
{rendered}
Expand Down
12 changes: 10 additions & 2 deletions src/test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ describe('compute positions', () => {
tooltipArrowReference: null,
})

expect(value).toEqual({ tooltipStyles: {}, tooltipArrowStyles: {}, place: 'top' })
expect(value).toEqual({
tooltipStyles: {},
tooltipArrowStyles: {},
place: 'top',
})
})

test('empty tooltip reference element', async () => {
Expand All @@ -20,7 +24,11 @@ describe('compute positions', () => {
tooltipArrowReference: null,
})

expect(value).toEqual({ tooltipStyles: {}, tooltipArrowStyles: {}, place: 'top' })
expect(value).toEqual({
tooltipStyles: {},
tooltipArrowStyles: {},
place: 'top',
})
})

test('empty tooltip arrow reference element', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compute-tooltip-position-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSSProperties } from 'react'
import type { CSSProperties } from 'react'
import type { Middleware, PlacesType } from '../components/Tooltip/TooltipTypes'

export interface IComputePositionArgs {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/compute-tooltip-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ const computeTooltipPosition = async ({
}
/* c8 ignore end */

return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement }
return {
tooltipStyles: styles,
tooltipArrowStyles: arrowStyle,
place: placement,
}
})
}

Expand Down
Loading
Loading