You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that we can use array to get the responsive value. But sometime I hope there is a function that put a object with readable key and output the array.
const__breakpointNameWithoutInitArray=['sm','md','lg','xl']asconst;if('_'in__breakpointNameWithoutInitArray){thrownewError(`Be sure that '_' cannot in the \`__breakpointNameWithoutInitArray\``,);}exporttypeBreakpointNameWithoutInit=typeof__breakpointNameWithoutInitArray[number];exporttypeBreakpointName=BreakpointNameWithoutInit|'_';exporttypeBreakpointMapWithoutInit={[sizeinBreakpointNameWithoutInit]: number;};exporttypeBreakpointMap={[sizeinBreakpointName]: number;};// Make breakpoints array and its name map(to breakpoints array's index).// e.g. makeBreakPoints([['640px', 'sm'], ['780px', 'md']]) === [['640px',// '780px'], {'sm': 0, 'md': 1}].constmakeBreakPoints=(breakpointsAndNames: Array<[string,BreakpointNameWithoutInit]>,): [Array<string>,BreakpointMapWithoutInit]=>{if(breakpointsAndNames.length!==__breakpointNameWithoutInitArray.length){thrownewError(`Be sure that those names ${__breakpointNameWithoutInitArray},`+"are all in the argument `breakpointsAndNames`'s breakpoints' names",);}letresult: [Array<string>,{[size: string]: number}]=[[],{}];letbreakpointNames=newSet();for(leti=0;i<breakpointsAndNames.length;i++){let[size,name]=breakpointsAndNames[i];// make sure breakpoint name is unique.if(nameinbreakpointNames){thrownewError("Be sure that breakpoint's name is unique.");}breakpointNames.add(name);result[0].push(size);result[1][name]=i;}return[result[0],result[1]asBreakpointMapWithoutInit];};const[breakpoints,breakpointNames]=makeBreakPoints([['640px','sm'],// breakpoint 0['780px','md'],// breakpoint 1['1024px','lg'],// breakpoint 2['1536px','xl'],// breakpoint 3]);// Make responsive value. (alias: mRV).// e.g. If breakpointNames(should use `makeBreakPoints` to make) is {'sm': 0,// 'md': 1, 'lg': 2, 'xl': 3}, then mRV<string>({_: '10px', 'md': '20px'}) ===// ['10px', null, '20px', null, null].exportconstmakeResponsiveValue=<T>(
argument: Partial<{[sizeinBreakpointName]: T}>,): (T|null)[]=>{letresult: (T|null)[]=fill(Array(breakpoints.length+1),null);for(constsinargument){constsize=sasBreakpointName;constvalue=argument[size];if(isUndefined(value))continue;if(size==='_'){result[0]=value;continue;}result[breakpointNames[size]+1]=value;}returnresult;};exportconstmRV=makeResponsiveValue;
The text was updated successfully, but these errors were encountered:
I know that we can use array to get the responsive value. But sometime I hope there is a function that put a object with readable key and output the array.
Here is my solution:
The text was updated successfully, but these errors were encountered: