Previews

No matching results.

x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- Default (No Rounding) -->
<span title="1,234" data-view-component="true" class="Counter">1,234</span>
<!-- Rounded Above 1,000 -->
<span title="1,234" data-view-component="true" class="Counter">1.2k</span>
<!-- Rounded Below 1,000 -->
<span title="999" data-view-component="true" class="Counter">999</span>
<!-- Rounded Large Numbers w/ Default Limit -->
<span title="5,000+" data-view-component="true" class="Counter">5k+</span>
<!-- Rounded Large Numbers, Less Than Custom Limit -->
<span title="4,567,890" data-view-component="true" class="Counter">4.6m</span>
<!-- Rounded Large Numbers, Greater Than Custom Limit -->
<span title="1,000,000+" data-view-component="true" class="Counter">1m+</span>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Default (No Rounding)
render(Primer::Beta::Counter.new(count: 1_234))
# Rounded Above 1,000
render(Primer::Beta::Counter.new(count: 1_234, round: true))
# Rounded Below 1,000
render(Primer::Beta::Counter.new(count: 999, round: true))
# Rounded Large Numbers w/ Default Limit
render(Primer::Beta::Counter.new(count: 4_567_890, round: true))
# Rounded Large Numbers, Less Than Custom Limit
render(Primer::Beta::Counter.new(count: 4_567_890, limit: 1_000_000_000, round: true))
# Rounded Large Numbers, Greater Than Custom Limit
render(Primer::Beta::Counter.new(count: 4_567_890, limit: 1_000_000, round: true))

app/components/primer/beta/counter.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Counter */
.Counter {
display: inline-block;
min-width: var(--base-size-20); /* makes sure it's a circle with just one digit */
padding: 0 var(--base-size-6);
font-size: var(--text-body-size-small);
font-weight: var(--base-text-weight-medium);
/* stylelint-disable-next-line primer/typography */
line-height: calc(var(--base-size-20) - var(--borderWidth-thin) * 2); /* 20px - 2px for the borders */
color: var(--fgColor-default);
text-align: center;
background-color: var(--bgColor-neutral-muted, var(--color-neutral-muted));
border: var(--borderWidth-thin) solid var(--counter-borderColor);
/* stylelint-disable-next-line primer/borders */
border-radius: 2em;
}
.Counter:empty {
display: none;
}
/* Is this selector used? could not find any use of it */
.Counter .octicon {
vertical-align: text-top;
opacity: 0.8;
}
.Counter--primary {
color: var(--fgColor-onEmphasis);
background-color: var(--bgColor-neutral-emphasis);
}
.Counter--secondary {
color: var(--fgColor-muted);
background-color: var(--bgColor-neutral-muted);
}