Skip to content

Commit

Permalink
Add support for mutation signals
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Dec 16, 2024
1 parent 5caf4d6 commit 9c8947e
Show file tree
Hide file tree
Showing 72 changed files with 4,845 additions and 347 deletions.
7 changes: 7 additions & 0 deletions .changeset/wicked-tomatoes-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@segment/analytics-signals': minor
'@segment/analytics-signals-runtime': minor
---

- Add support for interaction signals for custom components and elements with contenteditable property
- Allow custom disallow list to override network signals, even if same domain.
32 changes: 15 additions & 17 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--testTimeout=100000",
"--findRelatedTests",
"${relativeFile}"
],
"args": ["--testTimeout=100000", "--findRelatedTests", "${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
Expand All @@ -30,9 +24,17 @@
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
},
{
"name": "Run Jest Tests for Current Package",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--testTimeout=100000"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"cwd": "${fileDirname}"
},
{
"type": "node",
Expand All @@ -47,9 +49,7 @@
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
Expand All @@ -64,9 +64,7 @@
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"skipFiles": [
"<node_internals>/**"
]
"skipFiles": ["<node_internals>/**"]
},
{
"name": "ts-node Current File",
Expand Down
7 changes: 7 additions & 0 deletions packages/signals/signals-integration-tests/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}
1 change: 1 addition & 0 deletions packages/signals/signals-integration-tests/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
playwright-report/
8 changes: 8 additions & 0 deletions packages/signals/signals-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
".": "yarn run -T turbo run --filter=@internal/signals-integration-tests...",
"build": "webpack",
"test": "playwright test",
"test:vanilla": "playwright test src/tests/vanilla",
"test:perf": "playwright test src/tests/performance",
"test:custom": "playwright test src/tests/custom",
"watch": "webpack -w",
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"concurrently": "yarn run -T concurrently",
Expand All @@ -25,8 +28,13 @@
"@playwright/test": "^1.28.1",
"@segment/analytics-next": "workspace:^",
"@segment/analytics-signals": "workspace:^",
"@types/react": "^18.0.0",
"@types/react-dom": "^18",
"globby": "^11.0.2",
"http-server": "14.1.1",
"react": "^18.0.0",
"react-aria-components": "^1.5.0",
"react-dom": "^18.0.0",
"tslib": "^2.4.1",
"webpack": "^5.76.0",
"webpack-cli": "^4.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ const config: PlaywrightTestConfig = {
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: [['html', { open: 'never' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on',
launchOptions: {
args: ['--enable-precise-memory-info', '--js-flags=--expose-gc'],
},
},

/* Configure projects for major browsers */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function waitForCondition(
resolve()
} else if (Date.now() - startTime >= timeout) {
clearInterval(interval)
reject(new Error(errorMessage))
reject(new Error(`${errorMessage}. Timeout: ${timeout}ms`))
}
} catch (error) {
clearInterval(interval)
Expand Down
1 change: 1 addition & 0 deletions packages/signals/signals-integration-tests/src/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ declare global {
interface Window {
analytics: AnalyticsBrowser
signalsPlugin: SignalsPlugin
SignalsPlugin: typeof SignalsPlugin
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'
import { TextField } from './TextField'
import { Select, SelectItem } from './Select'

export const App: React.FC = () => {
return (
<main>
<div id="textfield">
<h2>TextField</h2>
<TextField label="some-text-field" />
</div>
<div id="select">
<h2>Select</h2>
<Select>
<SelectItem>Chocolate</SelectItem>
<SelectItem>Mint</SelectItem>
<SelectItem>Strawberry</SelectItem>
<SelectItem>Vanilla</SelectItem>
</Select>
</div>
</main>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@import "./theme.css";

.react-aria-Button {
color: var(--text-color);
background: var(--button-background);
border: 1px solid var(--border-color);
border-radius: 4px;
appearance: none;
vertical-align: middle;
font-size: 1rem;
text-align: center;
margin: 0;
outline: none;
padding: 6px 10px;
text-decoration: none;

&[data-pressed] {
box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.1);
background: var(--button-background-pressed);
border-color: var(--border-color-pressed);
}

&[data-focus-visible] {
outline: 2px solid var(--focus-ring-color);
outline-offset: -1px;
}

&[data-disabled]{
border-color: var(--border-color-disabled);
color: var(--text-color-disabled);
}
}

@keyframes toggle {
from {
opacity: 0;
}

to {
opacity: 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'
import { Button as RACButton, ButtonProps } from 'react-aria-components'
import './Button.css'

export function Button(props: ButtonProps) {
return <RACButton {...props} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@import "./theme.css";

.react-aria-Checkbox {
--selected-color: var(--highlight-background);
--selected-color-pressed: var(--highlight-background-pressed);
--checkmark-color: var(--highlight-foreground);

display: flex;
align-items: center;
gap: 0.571rem;
font-size: 1.143rem;
color: var(--text-color);
forced-color-adjust: none;

.checkbox {
width: 1.143rem;
height: 1.143rem;
border: 2px solid var(--border-color);
border-radius: 4px;
transition: all 200ms;
display: flex;
align-items: center;
justify-content: center;
}

svg {
width: 1rem;
height: 1rem;
fill: none;
stroke: var(--checkmark-color);
stroke-width: 3px;
stroke-dasharray: 22px;
stroke-dashoffset: 66;
transition: all 200ms;
}

&[data-pressed] .checkbox {
border-color: var(--border-color-pressed);
}

&[data-focus-visible] .checkbox {
outline: 2px solid var(--focus-ring-color);
outline-offset: 2px;
}

&[data-selected],
&[data-indeterminate] {
.checkbox {
border-color: var(--selected-color);
background: var(--selected-color);
}

&[data-pressed] .checkbox {
border-color: var(--selected-color-pressed);
background: var(--selected-color-pressed);
}

svg {
stroke-dashoffset: 44;
}
}

&[data-indeterminate] {
& svg {
stroke: none;
fill: var(--checkmark-color);
}
}

&[data-invalid] {
.checkbox {
--checkmark-color: var(--gray-50);
border-color: var(--invalid-color);
}

&[data-pressed] .checkbox {
border-color: var(--invalid-color-pressed);
}

&[data-selected],
&[data-indeterminate] {
.checkbox {
background: var(--invalid-color);
}

&[data-pressed] .checkbox {
background: var(--invalid-color-pressed);
}
}
}

&[data-disabled] {
color: var(--text-color-disabled);

.checkbox {
border-color: var(--border-color-disabled);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Checkbox as AriaCheckbox, CheckboxProps } from 'react-aria-components'
import React from 'react'
import './Checkbox.css'

export function Checkbox({ children, ...props }: CheckboxProps) {
return (
<AriaCheckbox {...props}>
{({ isIndeterminate }) => (
<>
<div className="checkbox">
<svg viewBox="0 0 18 18" aria-hidden="true">
{isIndeterminate ? (
<rect x={1} y={7.5} width={15} height={3} />
) : (
<polyline points="1 9 7 14 15 4" />
)}
</svg>
</div>
{children}
</>
)}
</AriaCheckbox>
)
}

export { Checkbox as MyCheckbox }
Loading

0 comments on commit 9c8947e

Please sign in to comment.