Skip to content

Commit

Permalink
fix weird radio labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kolodny committed Jan 15, 2024
1 parent e5441bc commit 92f2f39
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
8 changes: 5 additions & 3 deletions examples/vite-react-ts/src/report/hover.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';

export const Hover: React.FunctionComponent<{
style?: React.CSSProperties;
children: (hover: boolean) => React.ReactNode;
}> = ({ children }) => {
}> = ({ children, style }) => {
const [hover, setHover] = React.useState(false);
return (
<div
<span
style={style}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
{children(hover)}
</div>
</span>
);
};
38 changes: 17 additions & 21 deletions examples/vite-react-ts/src/report/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,34 @@ export const Radio: React.FunctionComponent<Props> = (props) => {
const selectedValue = controls ? controls.index : uncontrolled;
return (
<>
<div className="radio" style={{ display: 'inline-flex' }}>
<div className='radio'>
{options.map((option, index) => (
<Hover key={index}>
<Hover key={index} style={{ marginRight: 4 }}>
{(hover) => (
<div
key={index}
<label
style={{
cursor: 'pointer',
display: 'inline-flex',
// padding: 8,
background: hover
? '#ddd'
: index === selectedValue
? '#eee'
: '#fff',
? '#eee'
: '#fff',
transition: 'background 0.2s ease',
borderRadius: 4,
paddingRight: 8,
marginRight: 4,
border: 'none',
padding: 8,
cursor: 'pointer',
}}
>
<label style={{ cursor: 'pointer' }}>
<input
style={{ display: 'none' }}
type="radio"
value={index}
checked={index === selectedValue}
onChange={() => changeHandler(index)}
/>
{option}
</label>
</div>
<input
style={{ display: 'none' }}
type='radio'
value={index}
checked={index === selectedValue}
onChange={() => changeHandler(index)}
/>
{option}
</label>
)}
</Hover>
))}
Expand Down
6 changes: 3 additions & 3 deletions examples/vite-react-ts/src/report/report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ export const Report: React.FunctionComponent<Props> = ({
<Radio
options={statusFilters.map((s) => {
const label = upperFirst(s);
return `${statusIcons[s as 'passed'] ?? ''} ${label} (${
statusCounts[s] ?? 0
})`;
const withLabel = `${statusIcons[s as 'passed'] ?? ''} ${label} (${statusCounts[s] ?? 0
})`;
return <div style={{ padding: 8 }}>{withLabel}</div>;
})}
defaultIndex={statusFilters.indexOf(showing!)}
onChange={(e) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-react-ts/src/report/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Tabs: React.FunctionComponent<{ tabs: Tab[] }> = ({ tabs }) => {
const { Radio } = React.useContext(ComponentsContext);
return (
<>
<div style={{ padding: '0 8px' }}>
<div>
<Radio
defaultIndex={0}
options={tabs.map((t) => t.title)}
Expand Down
8 changes: 4 additions & 4 deletions examples/vite-react-ts/src/report/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const Test: React.FunctionComponent<
if (rendered.length) {
if (rendered.length === 1) {
tabs.push({
title: upperFirst(type),
title: <div style={{ padding: 8 }}>{upperFirst(type)}</div>,
content: rendered[0]?.item,
});
} else if (rendered?.length) {
const subTabs: Tab[] = [];
for (const render of rendered) {
subTabs.push({
title: upperFirst(render?.title),
title: <div style={{ padding: 8 }}>{upperFirst(render?.title)}</div>,
content: render?.item,
});
}
Expand All @@ -65,7 +65,7 @@ export const Test: React.FunctionComponent<

if (content?.length) {
tabs.push({
title,
title: <div style={{ padding: 8 }}>{title}</div>,
content: content.map((child, i) => (
<div key={i} style={{ marginBottom: 8 }} children={child} />
)),
Expand All @@ -81,7 +81,7 @@ export const Test: React.FunctionComponent<
tabs.push({
title: (
<span
style={{ padding: '8px 0' }}
style={{ padding: 8 }}
onClick={(e) => {
e.preventDefault();
window.open(testUrl, '_blank');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "safetest",
"version": "0.1.7",
"version": "0.1.8",
"description": "Safetest is a powerful UI testing library that combines Playwright, Jest, and React for a powerful end-to-end testing solution for applications and component testing. With Safetest, you can easily test the functionality and appearance of your application, ensuring that it works as expected and looks great on all devices.",
"main": "lib/index.js",
"bin": "./lib/cli.js",
Expand Down

0 comments on commit 92f2f39

Please sign in to comment.