Skip to content

Commit

Permalink
feat: support lower-latin and upper-latin list prefix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 4468e5c commit 4d4805c
Showing 1 changed file with 49 additions and 33 deletions.
82 changes: 49 additions & 33 deletions packages/render-html/src/elements/usePrefixRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,59 @@ const DecimalPrefixRenderer = ({
return <TextualPrefixRenderer {...props} prefix={index + 1 + '.'} />;
};

interface PrefixSepcs {
interface PrefixSpecs {
Component: ComponentType<ListPrefixRendererProps>;
computeStrSize(length: number): number;
}

const prefixRenderersMap: Record<SupportedListStyleType, PrefixSepcs> = ({
none: {
Component: NoPrefixRenderer,
computeStrSize: () => 0
},
disc: {
Component: DiscPrefixRenderer,
computeStrSize: () => 1
},
circle: {
Component: CirclePrefixRenderer,
computeStrSize: () => 1
},
square: {
Component: SquarePrefixRenderer,
computeStrSize: () => 1
},
decimal: {
Component: DecimalPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 10)
},
'lower-alpha': {
Component: LowerAlphaPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 26)
},
'upper-alpha': {
Component: UpperAlphaPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 26)
}
} as Partial<Record<SupportedListStyleType, PrefixSepcs>>) as Record<
const none: PrefixSpecs = {
Component: NoPrefixRenderer,
computeStrSize: () => 0
};

const disc: PrefixSpecs = {
Component: DiscPrefixRenderer,
computeStrSize: () => 1
};

const circle: PrefixSpecs = {
Component: CirclePrefixRenderer,
computeStrSize: () => 1
};

const square: PrefixSpecs = {
Component: SquarePrefixRenderer,
computeStrSize: () => 1
};

const decimal: PrefixSpecs = {
Component: DecimalPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 10)
};

const lowerAlpha: PrefixSpecs = {
Component: LowerAlphaPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 26)
};

const upperAlpha: PrefixSpecs = {
Component: UpperAlphaPrefixRenderer,
computeStrSize: (length) => numOfCharsInPrefix(length, 26)
};

const prefixRenderersMap: Record<SupportedListStyleType, PrefixSpecs> = ({
none,
disc,
circle,
square,
decimal,
'lower-alpha': lowerAlpha,
'upper-alpha': upperAlpha,
'lower-latin': lowerAlpha,
'upper-latin': upperAlpha
} as Partial<Record<SupportedListStyleType, PrefixSpecs>>) as Record<
SupportedListStyleType,
PrefixSepcs
PrefixSpecs
>;

export type SupportedListStyleType =
Expand Down Expand Up @@ -190,7 +206,7 @@ export default function usePrefixRenderer({
listStyleType,
getListStyleTypeFromNestLevel,
nestLevel
}: HTMLListPrefixProps): PrefixSepcs {
}: HTMLListPrefixProps): PrefixSpecs {
const selectedListType = getListStyleTypeFromNestLevel(nestLevel);
return listStyleType
? prefixRenderersMap[listStyleType as SupportedListStyleType] ||
Expand Down

0 comments on commit 4d4805c

Please sign in to comment.