-
Notifications
You must be signed in to change notification settings - Fork 11
feat: custom modal dimension #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8bf3da5
5599c6a
88d3bd4
cd18474
2aa1a9b
111e41d
9b40fc4
00b1e07
f81b19d
423dc6d
9466514
b2b04ba
1e2e570
403a9d4
a74bd5d
5d47c7f
60746c3
94374ed
29c7ed5
d5fc366
cf7774e
d6d65ad
b14e30a
f2084a1
ed028d6
c5a2226
5c7bfdd
35d133a
a3826cb
b18ede0
f3dc565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,8 @@ import { InjectionToken, TemplateRef, Type } from '@angular/core'; | |
| import { Observable } from 'rxjs'; | ||
|
|
||
| export interface ModalConfig<TData = unknown> { | ||
| size: ModalSize; | ||
| content: TemplateRef<unknown> | Type<unknown>; | ||
| size: ModalSize | ModalDimension; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm... this kind of makes the design weird. The same property is trying to do two things. What if, we introduce a new enum in ModalSize called Alternatively, the config itself can change for custom size. @aaron-steinfeld thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree. It's serving the same role in either case - a way to specify the size. Every other option is the same, so it doesn't make sense to have two versions of the config or an optional property (since the optional property is meaningless depending on the enum value). This is the beauty of unions - it's a strictly easier API for the caller to work with. Any messiness is internal to the implementation, and disambiguating between types should really just be a one liner.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine. I don't have strong feelings. I find it weird when we put type based logic in the code. IMO, keeping separate properties makes it cleaner from API perspective. But it is a preference |
||
| showControls?: boolean; | ||
| title?: string; | ||
| data?: TData; | ||
|
|
@@ -19,6 +19,33 @@ export const enum ModalSize { | |
| MediumWide = 'medium-wide' | ||
| } | ||
|
|
||
| export interface ModalDimension { | ||
| // Number => without unit (considered px) and String => with units (expression included) | ||
| width: number | string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I pass a random string?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, it won't work at that time. And I think this should be the case. Like suppose if we do this in the css (putting wrong value for width), then it doesn't work. So It is developer's responsibility to put correct value and I think developer can handle this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to get really fancy, TS supports this kind of thing now. I'd also be fine just taking in any string, we don't validate to nearly this level elsewhere. type Unit = "px" | "em" | "fr" | "%"; // probably some others too
type SizeWithUnit = `${number}${Unit}`;
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we could do this, but my intention of using string, to use these kind of expression as well, not only simple units -
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type SizeExpression = SizeWithUnit | `calc(${SizeWithUnit} - ${SizeWithUnit})`Typescript type system is turing complete 😉 But seriously, yes I agree, overkill.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah!!!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will let you guys decide :D
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to me, It is good enough and as @aaron-steinfeld said doing this, is an overkill. |
||
| height: number | string; | ||
| } | ||
|
|
||
| export const getModalDimensions = (modalSize: ModalSize): ModalDimension => { | ||
| switch (modalSize) { | ||
| case ModalSize.Small: | ||
| return getModalDimensionObject(420, 365); | ||
| case ModalSize.Medium: | ||
| return getModalDimensionObject(456, 530); | ||
| case ModalSize.LargeShort: | ||
| return getModalDimensionObject(640, 540); | ||
| case ModalSize.Large: | ||
| return getModalDimensionObject(640, 720); | ||
| case ModalSize.LargeTall: | ||
| return getModalDimensionObject(640, 800); | ||
| case ModalSize.MediumWide: | ||
| return getModalDimensionObject(840, 600); | ||
| default: | ||
| return getModalDimensionObject(420, 365); | ||
| } | ||
| }; | ||
|
|
||
| const getModalDimensionObject = (width: number, height: number): ModalDimension => ({ width: width, height: height }); | ||
|
|
||
| export const MODAL_DATA = new InjectionToken<unknown>('MODAL_DATA'); | ||
|
|
||
| export abstract class ModalRef<TResult> { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.