This browser is not supported. The glass needs a Chromium browser or Electron. Why

Gauge

A value within a range, drawn as a bar or a ring in any of the SwiftUI gauge styles. Flat, as on iOS: no glass.

import { Gauge } from "@adamexu/glass";

Bars and rings

automatic is linearCapacity, a thick bar with the label (children) over it. The accessory styles are the compact ones iOS draws in a widget: accessoryLinear is a line with a dot at the value, accessoryLinearCapacity a thin bar, and the circular ones are an open ring with a dot or a closed ring that fills.

Storage0128 GB
01
Steps
211030
80
<Gauge value={0.62} minimumValueLabel="0" maximumValueLabel="128 GB">Storage</Gauge>
<Gauge value={0.4} gaugeStyle="accessoryLinear" minimumValueLabel="0" maximumValueLabel="1" aria-label="Load" />
<Gauge value={0.75} gaugeStyle="accessoryLinearCapacity">Steps</Gauge>
<Gauge value={21} in={[10, 30]} gaugeStyle="accessoryCircular" currentValueLabel="21" minimumValueLabel="10" maximumValueLabel="30">
  Temperature
</Gauge>
<Gauge value={0.8} gaugeStyle="accessoryCircularCapacity" tint="#0088FF" aria-label="Done">80</Gauge>

Animated

With animated (a change under withAnimation) the default bar eases to a new value on a critically damped spring, on the compositor. Without it, and in the accessory styles, a change is a step. A tint array is a gradient whose stops span the whole bar, whatever the value.

Battery70%
Gradient
const [level, setLevel] = useState(0.7);

<Gauge value={level} animated currentValueLabel={`${Math.round(level * 100)}%`}>
  Battery
</Gauge>
<Gauge value={level} animated tint={["#FF2D55", "#34C759"]}>
  Gradient
</Gauge>
<Button buttonStyle="plain" onClick={() => setLevel((g) => (g > 0.5 ? 0.2 : 0.9))}>
  Change the gauge
</Button>

In a List

<NavigationStack
  root={
    <NavigationPage title="Device">
      <List>
        <Section header="Gauge">
          <Gauge value={level} animated={animated} currentValueLabel={`${Math.round(level * 100)}%`} minimumValueLabel="0" maximumValueLabel="1">
            <Text>Battery</Text>
          </Gauge>
          <Gauge value={level} animated={animated} gaugeStyle="accessoryLinearCapacity">
            <Text>Battery</Text>
          </Gauge>
          <Button
            buttonStyle="plain"
            onClick={() => {
              setAnimated(true);
              setLevel((g) => (g > 0.5 ? 0.2 : 0.9));
            }}
          >
            Change the gauge (withAnimation)
          </Button>
        </Section>
      </List>
    </NavigationPage>
  }
/>

Props

PropTypeDefaultDescription
valuenumber-Required. Clamped to the range.
inreadonly [number, number][0, 1]The range.
gaugeStyle"automatic" | "linearCapacity" | "accessoryLinear" | "accessoryLinearCapacity" | "accessoryCircular" | "accessoryCircularCapacity""automatic"automatic is linearCapacity. accessoryLinearCapacity is drawn as a ProgressView bar.
childrenReactNode-The label: over the bar, in the open ring when there is no currentValueLabel, in the closed ring's center.
currentValueLabelReactNode-The value as text: under the bar, in the ring.
minimumValueLabelReactNode-The low end's label, beside the bar or under the ring.
maximumValueLabelReactNode-The high end's label.
tintstring | readonly string[]-A colour, or a gradient's colours across the whole default bar (the accessory styles take a single colour).
animatedbooleanfalseThe default bar eases to a new value on a spring.
disabledbooleanfalseAccepted and ignored: .disabled doesn't change a Gauge.
aria-labelstring-On the role="meter" element; a string label names it otherwise.
className, stylestring, CSSProperties-On the same element.

SwiftUI

SwiftUI@adamexu/glass
Gauge(value:, in:) { label } currentValueLabel: { }<Gauge value in currentValueLabel>label</Gauge>
minimumValueLabel: { } maximumValueLabel: { }minimumValueLabel maximumValueLabel
.gaugeStyle(.accessoryCircular)gaugeStyle="accessoryCircular"
.tint(Gradient(colors: [a, b]))tint={[a, b]}
withAnimation { value = x } on a Gaugeanimated