-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: include minimum breakpoints required
- Loading branch information
Showing
5 changed files
with
78 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { StudioComponent } from '../types'; | ||
|
||
export const breakpointSizes = ['base', 'small', 'medium', 'large', 'xl', 'xxl'] as const; | ||
export type BreakpointSizeType = typeof breakpointSizes[number]; | ||
export const bpWeights: Record<BreakpointSizeType, number> = { | ||
base: 0, | ||
small: 1, | ||
medium: 2, | ||
large: 3, | ||
xl: 4, | ||
xxl: 5, | ||
}; | ||
|
||
/** | ||
* sorts the breakpoints to the following order | ||
* | ||
* ['base', 'small', 'medium', 'large', 'xl', 'xxl'] | ||
*/ | ||
export const sortBreakpoints = (bs: BreakpointSizeType[]): BreakpointSizeType[] => { | ||
return bs.sort((lhs, rhs) => { | ||
return bpWeights[lhs] - bpWeights[rhs]; | ||
}); | ||
}; | ||
|
||
export const getBreakpoints = (component: StudioComponent & Required<Pick<StudioComponent, 'variants'>>) => { | ||
const breakpoints = component.variants.reduce<BreakpointSizeType[]>((acc, variant) => { | ||
if (variant.variantValues?.breakpoint) { | ||
acc.push(variant.variantValues.breakpoint as BreakpointSizeType); | ||
} | ||
return acc; | ||
}, []); | ||
return sortBreakpoints(breakpoints); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters