Skip to content

Feature proposal: context properties #3508

@jpnurmi

Description

@jpnurmi

It would be nice to have a way to propagate information to children without explicitly passing them as properties on each level aka. "property drilling".

enum ThemeMode { light, dark }

context Theme {
    property<ThemeMode> mode;
    property<brush> background;
    property<brush> foreground;
}

// Adapts its looks according to the theme in the context
component MyThemableWidget {
    Rectangle {
        background: Theme.background; // <--
        Text {
            color: Theme.foreground; // <--
        }
    }
}

export component MyWindow inherits Window {
    Theme {
        mode: ThemeMode.light;
        MyThemableWidget {}
    }

    Theme {
        mode: ThemeMode.dark;
        Dialog {
            MyThemableWidget {}
        }
    }
}

This is conceptually similar to Context in React and InheritedWidget in Flutter. In Flutter, inherited widgets are used for implementing many core framework features including theming, localization, layout direction, navigation, and many external packages for dependency injection and state management.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:language-slintCompiler for the .slint language (mO,bF)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions