Skip to content

Commit

Permalink
feat: support decimal-leading-zero list style type prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 4d4805c commit 526e226
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/render-html/src/elements/usePrefixRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ const DecimalPrefixRenderer = ({
return <TextualPrefixRenderer {...props} prefix={index + 1 + '.'} />;
};

const DecimalLeadingZeroPrefixRenderer = ({
index,
...props
}: ListPrefixRendererProps) => {
const syntheticIndex = index + 1;
return (
<TextualPrefixRenderer
{...props}
prefix={`${syntheticIndex < 10 ? `0${syntheticIndex}` : syntheticIndex}.`}
/>
);
};

interface PrefixSpecs {
Component: ComponentType<ListPrefixRendererProps>;
computeStrSize(length: number): number;
Expand Down Expand Up @@ -154,6 +167,11 @@ const decimal: PrefixSpecs = {
computeStrSize: (length) => numOfCharsInPrefix(length, 10)
};

const decimalLeadingZero: PrefixSpecs = {
Component: DecimalLeadingZeroPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length < 10 ? 10 : length, 10)
};

const lowerAlpha: PrefixSpecs = {
Component: LowerAlphaPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 26)
Expand All @@ -173,7 +191,8 @@ const prefixRenderersMap: Record<SupportedListStyleType, PrefixSpecs> = ({
'lower-alpha': lowerAlpha,
'upper-alpha': upperAlpha,
'lower-latin': lowerAlpha,
'upper-latin': upperAlpha
'upper-latin': upperAlpha,
'decimal-leading-zero': decimalLeadingZero
} as Partial<Record<SupportedListStyleType, PrefixSpecs>>) as Record<
SupportedListStyleType,
PrefixSpecs
Expand Down

0 comments on commit 526e226

Please sign in to comment.