Skip to content

Commit

Permalink
- add isDark for MediaQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrim0 committed Jan 1, 2025
1 parent 89c4bba commit 9ff2807
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions packages/jaspr/lib/src/foundation/styles/rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,44 @@ import 'styles.dart';

abstract class StyleRule {
/// Renders a css rule with the given selector and styles.
const factory StyleRule({required Selector selector, required Styles styles}) = BlockStyleRule;
const factory StyleRule({
required Selector selector,
required Styles styles,
}) = BlockStyleRule;

/// Renders a `@import url(...)` css rule.
const factory StyleRule.import(String url) = ImportStyleRule;

/// Renders a `@font-face` css rule.
const factory StyleRule.fontFace({required String family, FontStyle? style, required String url}) = FontFaceStyleRule;
const factory StyleRule.fontFace({
required String family,
FontStyle? style,
required String url,
}) = FontFaceStyleRule;

/// Renders a `@media` css rule.
const factory StyleRule.media({required MediaQuery query, required List<StyleRule> styles}) = MediaStyleRule;
const factory StyleRule.media({
required MediaQuery query,
required List<StyleRule> styles,
}) = MediaStyleRule;

/// Renders a `@layer` css rule.
const factory StyleRule.layer({String? name, required List<StyleRule> styles}) = LayerStyleRule;
const factory StyleRule.layer({
String? name,
required List<StyleRule> styles,
}) = LayerStyleRule;

/// Renders a `@supports` css rule.
const factory StyleRule.supports({required String condition, required List<StyleRule> styles}) = SupportsStyleRule;
const factory StyleRule.supports({
required String condition,
required List<StyleRule> styles,
}) = SupportsStyleRule;

/// Renders a `@keyframes` css rule.
const factory StyleRule.keyframes({required String name, required Map<String, Styles> styles}) = KeyframesStyleRule;
const factory StyleRule.keyframes({
required String name,
required Map<String, Styles> styles,
}) = KeyframesStyleRule;

/// Returns the rendered css for this rule.
String toCss([String indent]);
Expand Down Expand Up @@ -128,7 +147,9 @@ class _MediaRuleQuery implements MediaQuery {
this.orientation,
this.canHover,
this.aspectRatio,
this.isDark,
}) : target = 'all';

const _MediaRuleQuery.screen({
this.minWidth,
this.maxWidth,
Expand All @@ -137,7 +158,9 @@ class _MediaRuleQuery implements MediaQuery {
this.orientation,
this.canHover,
this.aspectRatio,
this.isDark,
}) : target = 'screen';

const _MediaRuleQuery.print({
this.minWidth,
this.maxWidth,
Expand All @@ -146,6 +169,7 @@ class _MediaRuleQuery implements MediaQuery {
this.orientation,
this.canHover,
this.aspectRatio,
this.isDark,
}) : target = 'print';

final String target;
Expand All @@ -156,6 +180,7 @@ class _MediaRuleQuery implements MediaQuery {
final Orientation? orientation;
final bool? canHover;
final String? aspectRatio;
final bool? isDark;

@override
String get _value => '$target'
Expand All @@ -165,6 +190,7 @@ class _MediaRuleQuery implements MediaQuery {
'${maxHeight != null ? ' and (max-height: ${maxHeight!.value})' : ''}'
'${orientation != null ? ' and (orientation: ${orientation!.name})' : ''}'
'${canHover != null ? ' and (hover: ${canHover! ? 'hover' : 'none'})' : ''}'
'${isDark != null ? ' and (prefers-color-scheme: ${isDark! ? 'dark' : 'light'})' : ''}'
'${aspectRatio != null ? ' and (aspect-ratio: ${aspectRatio!})' : ''}';
}

Expand Down Expand Up @@ -208,7 +234,11 @@ class ImportStyleRule implements StyleRule {
}

class FontFaceStyleRule implements StyleRule {
const FontFaceStyleRule({required this.family, this.style, required this.url});
const FontFaceStyleRule({
required this.family,
this.style,
required this.url,
});

final String family;
final FontStyle? style;
Expand Down

0 comments on commit 9ff2807

Please sign in to comment.