# All files / typography typography.tsx

100% Statements 16/16
75% Branches 3/4
100% Functions 5/5
100% Lines 16/16

    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    751x

    1x
    1x
    1x

    1x

    1x

    1x

    16x

    16x

    16x

    16x

    16x

    16x

    1x
    1x
    1x
     import * as React from "react";
    import * as ReactDOM from "react-dom";
    import { get } from "lodash-es";
    import Foundation, { HandledProps } from "@microsoft/fast-components-foundation-react";
    import {
        TypographyHandledProps,
        TypographyManagedClasses,
        TypographyProps,
        TypographySize,
        TypographyTag,
        TypographyUnhandledProps
    } from "./typography.props";
    import { ManagedClasses, TypographyClassNameContract } from "@microsoft/fast-components-class-name-contracts-base";

    class Typography extends Foundation<
        TypographyHandledProps,
        TypographyUnhandledProps,
        {}
    > {
        public static defaultProps: Partial<TypographyProps> = {
            tag: TypographyTag.p
        };

        public static displayName: string = "Typography";

        protected handledProps: HandledProps<TypographyHandledProps> = {
            managedClasses: void 0,
            tag: void 0,
            size: void 0
        };

        /**
         * Stores HTML tag for use in render
         */
        private get tag(): string {
            return this.generateHTMLTag();
        }

        /**
         * Renders the component
         */
        public render(): React.ReactElement<HTMLHeadingElement | HTMLParagraphElement | HTMLSpanElement | HTMLTableCaptionElement> {
            return (
                <this.tag
                    {...this.unhandledProps()}
                    className={this.generateClassNames()}
                >
                    {this.props.children}
                </this.tag>
            );
        }

        /**
         * Generates class names based on props
         */
        protected generateClassNames(): string {
            const classes: string = this.props.size
                ? get(this.props, `managedClasses.typography__${this.props.size}`)
                : get(this.props, "managedClasses.typography__1");

            return super.generateClassNames(`${get(this.props, "managedClasses.typography")} ${classes}`);
        }

        /**
         * Creates tags for rendering based on href
         */
        private generateHTMLTag(): string {
            return TypographyTag[this.props.tag] || TypographyTag.p;
        }
    }

    export default Typography;
    export * from "./typography.props";
    export { TypographyClassNameContract };