summaryrefslogtreecommitdiff
path: root/components/controls/CollapsibleSection.qml
blob: 945386c0e16f7971cb3c5cf47cc7f36d4c1664ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import ".."
import qs.components
import qs.components.effects
import qs.services
import qs.config
import QtQuick
import QtQuick.Layouts

ColumnLayout {
    id: root

    required property string title
    property string description: ""
    property bool expanded: false
    
    signal toggleRequested

    spacing: Appearance.spacing.small / 2
    Layout.fillWidth: true

    Item {
        id: sectionHeaderItem
        Layout.fillWidth: true
        Layout.preferredHeight: sectionHeader.implicitHeight

        ColumnLayout {
            id: sectionHeader
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: Appearance.spacing.small

            RowLayout {
                Layout.fillWidth: true
                spacing: Appearance.spacing.small

                StyledText {
                    Layout.topMargin: Appearance.spacing.large
                    text: root.title
                    font.pointSize: Appearance.font.size.larger
                    font.weight: 500
                }

                Item {
                    Layout.fillWidth: true
                }

                MaterialIcon {
                    text: "expand_more"
                    rotation: root.expanded ? 180 : 0
                    color: Colours.palette.m3onSurface
                    Behavior on rotation {
                        Anim {}
                    }
                }
            }

            StateLayer {
                anchors.fill: parent
                anchors.leftMargin: -Appearance.padding.normal
                anchors.rightMargin: -Appearance.padding.normal
                function onClicked(): void {
                    root.toggleRequested();
                    root.expanded = !root.expanded;
                }
            }

            StyledText {
                visible: root.expanded && root.description !== ""
                text: root.description
                color: Colours.palette.m3outline
                Layout.fillWidth: true
            }
        }
    }

    default property alias content: contentColumn.data

    ColumnLayout {
        id: contentColumn
        Layout.fillWidth: true
        visible: root.expanded
        spacing: Appearance.spacing.small / 2
    }
}