Skip to content
Merged
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed `Pointer`, which was rendering a string in some context, instead of a JSX element

### Changed

- Changed `Scale`, which was skipped when no value was set to the component. Now it is rendered.
- Changed `RenderCustomProps`type, which is now valid for `percentage=null`

## 1.3.0 - 2026-01-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Pointer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function Pointer(props: React.PropsWithChildren<Props>) {
}, [percentage, angleOffset, angleRange, center, radius, height]);

if (transform === null) {
return '<></>';
return <></>;
}

return (
Expand Down
19 changes: 10 additions & 9 deletions lib/src/Scale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ interface RenderProps {
center: [number, number];
color?: string;
className?: string;

/**
* Id of the active tick.
*
* Can be `-1` if there is no active tick in this state.
*/
active: number;
activeColor?: string;
activeClassName?: string;
Expand Down Expand Up @@ -81,7 +87,7 @@ export interface RenderCustomProps extends RenderProps {
tickWidth: number;
tickHeight: number;
steps: number;
percentage: number;
percentage: number | null;
}

function renderCustom({
Expand All @@ -92,7 +98,7 @@ function renderCustom({
tickWidth: number;
tickHeight: number;
steps: number;
percentage: number;
percentage: number | null;
} & RenderProps) {
return (_: unknown, i: number) => fn({ ...props, i });
}
Expand Down Expand Up @@ -139,11 +145,9 @@ export function Scale(props: Props) {
const length = steps + (angleRange === 360 ? 0 : 1);
const translateX = center[0] - tickWidth / 2;
const translateY = center[1] - radius;
if (percentage === null) {
return <></>;
}

const active = Math.round((length - 1) * percentage);
const active =
percentage === null ? -1 : Math.round((length - 1) * percentage);

function getRenderFn() {
if (steps === undefined) {
Expand Down Expand Up @@ -181,9 +185,6 @@ export function Scale(props: Props) {
});
}
if (fn) {
if (percentage === null) {
return <></>;
}
return renderCustom({
fn,
tickWidth,
Expand Down
23 changes: 23 additions & 0 deletions lib/test/Scale.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,27 @@ describe('Scale', () => {
);
expect(container.children[0].children[0].children[0]).toMatchSnapshot();
});
it('renders when value is null', () => {
const { container } = render(
<Knob
min={0}
max={100}
value={null}
size={100}
angleOffset={90}
angleRange={200}
>
<Scale
type="circle"
steps={3}
radius={40}
tickWidth={2}
tickHeight={10}
className="someClassName"
activeClassName="someActiveClassName"
/>
</Knob>,
);
expect(container.children[0].children[0].children[0]).toMatchSnapshot();
});
});
41 changes: 41 additions & 0 deletions lib/test/__snapshots__/Scale.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,44 @@ exports[`Scale > renders correct with custom render function for ticks 1`] = `
/>
</g>
`;

exports[`Scale > renders when value is null 1`] = `
<g>
<circle
class="someClassName"
r="2"
stroke="none"
transform="
rotate(90 50 50)
translate(49 10)
"
/>
<circle
class="someClassName"
r="2"
stroke="none"
transform="
rotate(156.66666666666669 50 50)
translate(49 10)
"
/>
<circle
class="someClassName"
r="2"
stroke="none"
transform="
rotate(223.33333333333334 50 50)
translate(49 10)
"
/>
<circle
class="someClassName"
r="2"
stroke="none"
transform="
rotate(290 50 50)
translate(49 10)
"
/>
</g>
`;