# All files / label label.tsx

100% Statements 17/17
75% Branches 3/4
100% Functions 4/4
100% Lines 17/17

    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
    691x

    1x
    1x
    1x

    1x

    1x

    1x

    11x

    11x

    11x

    11x

    11x
    3x

    11x

    1x
    1x
    1x
     import * as React from "react";
    import * as ReactDOM from "react-dom";
    import { get, isUndefined } from "lodash-es";
    import Foundation, { HandledProps } from "@microsoft/fast-components-foundation-react";
    import {
        LabelHandledProps,
        LabelManagedClasses,
        LabelProps,
        LabelTag,
        LabelUnhandledProps
    } from "./label.props";
    import { LabelClassNameContract, ManagedClasses } from "@microsoft/fast-components-class-name-contracts-base";

    class Label extends Foundation<
        LabelHandledProps,
        LabelUnhandledProps,
        {}
    > {
        public static displayName: string = "Label";

        public static defaultProps: Partial<LabelProps> = {
            tag: LabelTag.label
        };

        protected handledProps: HandledProps<LabelHandledProps & ManagedClasses<LabelClassNameContract>> = {
            hidden: void 0,
            managedClasses: void 0,
            tag: void 0
        };

        /**
         * Stores HTML tag for use in render
         */
        private get tag(): string {
            return isUndefined(LabelTag[this.props.tag]) ? LabelTag.label : LabelTag[this.props.tag];
        }

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

        /**
         * Generates class names based on props
         */
        protected generateClassNames(): string {
            let className: string = get(this.props, "managedClasses.label");

            if (this.props.hidden) {
                className = `${className} ${get(this.props, "managedClasses.label__hidden")}`;
            }

            return super.generateClassNames(className);
        }
    }

    export default Label;
    export * from "./label.props";
    export { LabelClassNameContract };