All files / src/components/zd-month month.ts

100% Statements 20/20
100% Branches 8/8
100% Functions 3/3
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 9093x 93x           93x       16x         16x         16x   16x         16x   16x   16x             16x 16x 16x 16x       93x                               7x   7x       93x                               6x   6x      
import { Config, FormatterParserProvider } from '@zeedhi/core';
import { DateInput } from '../zd-date-input/date-input';
import { IMonth } from './interfaces';
 
/**
 * Base class for Month Picker component.
 */
export class Month extends DateInput implements IMonth {
	/**
	 * Defines the month format.
	 */
	public dateFormat: string = Config.monthFormat;
 
	/**
	 * Defines the month format displayed.
	 */
	public displayFormat: string = Config.monthDisplayFormat;
 
	/**
	 * Defines the month input format.
	 */
	public inputFormat?: string = Config.monthInputFormat;
 
	protected isoFormat = 'YYYY-MM';
 
	/**
	 * Determines the type of the view mode - month for month picker.
	 */
	public viewMode = 'months';
 
	protected formatterFn = FormatterParserProvider.getFormatter('ZdMonth');
 
	protected parserFn = FormatterParserProvider.getParser('ZdMonth');
 
	/**
	 * Creates a new Month picker.
	 * @param props Month properties
	 */
	constructor(props: IMonth) {
		super(props);
		this.dateFormat = this.getInitValue('dateFormat', props.dateFormat, this.dateFormat);
		this.displayFormat = this.getInitValue('displayFormat', props.displayFormat, this.displayFormat);
		this.inputFormat = this.getInitValue('inputFormat', props.inputFormat, this.inputFormat);
	}
}
 
FormatterParserProvider.registerFormatter(
	'ZdMonth',
	(
		value: string,
		{
			dateFormat = Config.monthFormat,
			displayFormat = Config.monthDisplayFormat,
			inputFormat = Config.monthInputFormat,
			isFocused,
		}: {
			dateFormat?: string;
			displayFormat?: string;
			inputFormat?: string;
			isFocused?: boolean;
		} = {},
	) => {
		const dateFormatter = FormatterParserProvider.getFormatter('ZdDateInput');
 
		return dateFormatter(value, { dateFormat, displayFormat, inputFormat, isFocused });
	},
);
 
FormatterParserProvider.registerParser(
	'ZdMonth',
	(
		value: string,
		{
			dateFormat = Config.monthFormat,
			displayFormat = Config.monthDisplayFormat,
			inputFormat = Config.monthInputFormat,
			isFocused,
		}: {
			dateFormat?: string;
			displayFormat?: string;
			inputFormat?: string;
			isFocused?: boolean;
		} = {},
	) => {
		const dateParser = FormatterParserProvider.getParser('ZdDateInput');
 
		return dateParser(value, { dateFormat, displayFormat, inputFormat, isFocused });
	},
);