15
15
*/
16
16
package com.breens.beetablescompose
17
17
18
+ import androidx.compose.foundation.BorderStroke
18
19
import androidx.compose.foundation.layout.Column
19
- import androidx.compose.foundation.rememberScrollState
20
20
import androidx.compose.foundation.shape.RoundedCornerShape
21
- import androidx.compose.foundation.verticalScroll
22
- import androidx.compose.material3.Card
23
21
import androidx.compose.material3.CardDefaults
24
22
import androidx.compose.material3.MaterialTheme
23
+ import androidx.compose.material3.OutlinedCard
25
24
import androidx.compose.runtime.Composable
26
- import androidx.compose.ui.Modifier
27
- import androidx.compose.ui.draw.clip
25
+ import androidx.compose.ui.Alignment
28
26
import androidx.compose.ui.graphics.Color
29
27
import androidx.compose.ui.text.TextStyle
28
+ import androidx.compose.ui.text.style.TextAlign
30
29
import androidx.compose.ui.unit.Dp
31
30
import androidx.compose.ui.unit.dp
32
31
import com.breens.beetablescompose.components.TableHeaderComponent
32
+ import com.breens.beetablescompose.components.TableHeaderComponentWithoutColumnDividers
33
33
import com.breens.beetablescompose.components.TableRowComponent
34
+ import com.breens.beetablescompose.components.TableRowComponentWithoutDividers
34
35
import com.breens.beetablescompose.utils.extractMembers
35
36
36
37
/* *
@@ -49,37 +50,68 @@ import com.breens.beetablescompose.utils.extractMembers
49
50
* @param rowTextStyle The text style to apply to the data cells in the table rows, by default it will be [MaterialTheme.typography.bodySmall].
50
51
* @param tableElevation The elevation of the entire table (Card elevation) in DP, by default it will be "6.dp".
51
52
* @param shape The shape of the table's corners, by default it will be "RoundedCornerShape(4.dp)".
53
+ * @param disableVerticalDividers show or hide the vertical dividers between the table cells. If not set, by default the vertical dividers will be shown.
54
+ * @param horizontalDividerThickness The thickness of the horizontal dividers in DP, by default it will be "1.dp". Note: This will only be visible if [disableVerticalDividers] is set to true.
55
+ * @param horizontalDividerColor The color of the horizontal dividers, by default it will be [Color.LightGray]. Note: This will only be visible if [disableVerticalDividers] is set to true.
56
+ * @param contentAlignment The alignment of the content in the table cells, by default it will be [Alignment.Center].
57
+ * @param textAlign The alignment of the text in the table cells, by default it will be [TextAlign.Center].
52
58
*/
53
59
@Composable
54
60
inline fun <reified T : Any > BeeTablesCompose (
55
61
data : List <T >,
56
62
enableTableHeaderTitles : Boolean = true,
57
63
headerTableTitles : List <String >,
58
64
headerTitlesBorderColor : Color = Color .LightGray ,
59
- headerTitlesBorderWidth : Dp = 0.4.dp,
60
65
headerTitlesTextStyle : TextStyle = MaterialTheme .typography.bodySmall,
61
66
headerTitlesBackGroundColor : Color = Color .White ,
62
67
tableRowColors : List <Color > = listOf(Color .White , Color .White ),
63
68
rowBorderColor : Color = Color .LightGray ,
64
- rowBorderWidth : Dp = 0.4.dp,
65
69
rowTextStyle : TextStyle = MaterialTheme .typography.bodySmall,
66
- tableElevation : Dp = 6 .dp,
70
+ tableElevation : Dp = 0 .dp,
67
71
shape : RoundedCornerShape = RoundedCornerShape (4.dp),
72
+ borderStroke : BorderStroke = BorderStroke (
73
+ width = 1.dp,
74
+ color = Color .LightGray ,
75
+ ),
76
+ disableVerticalDividers : Boolean = false,
77
+ dividerThickness : Dp = 1.dp,
78
+ horizontalDividerColor : Color = Color .LightGray ,
79
+ contentAlignment : Alignment = Alignment .Center ,
80
+ textAlign : TextAlign = TextAlign .Center ,
81
+ tablePadding : Dp = 0.dp,
82
+ columnToIndexIncreaseWidth : Int? = null,
68
83
) {
69
- Card (elevation = CardDefaults .cardElevation(defaultElevation = tableElevation)) {
70
- Column (
71
- modifier = Modifier
72
- .clip(shape = shape)
73
- .verticalScroll(rememberScrollState()),
74
- ) {
84
+ OutlinedCard (
85
+ elevation = CardDefaults .cardElevation(defaultElevation = tableElevation),
86
+ shape = shape,
87
+ border = borderStroke,
88
+ ) {
89
+ Column {
75
90
if (enableTableHeaderTitles) {
76
- TableHeaderComponent (
77
- headerTableTitles = headerTableTitles,
78
- headerTitlesBorderColor = headerTitlesBorderColor,
79
- headerTitlesBorderWidth = headerTitlesBorderWidth,
80
- headerTitlesTextStyle = headerTitlesTextStyle,
81
- headerTitlesBackGroundColor = headerTitlesBackGroundColor,
82
- )
91
+ if (disableVerticalDividers) {
92
+ TableHeaderComponentWithoutColumnDividers (
93
+ headerTableTitles = headerTableTitles,
94
+ headerTitlesTextStyle = headerTitlesTextStyle,
95
+ headerTitlesBackGroundColor = headerTitlesBackGroundColor,
96
+ dividerThickness = dividerThickness,
97
+ contentAlignment = contentAlignment,
98
+ textAlign = textAlign,
99
+ tablePadding = tablePadding,
100
+ columnToIndexIncreaseWidth = columnToIndexIncreaseWidth,
101
+ )
102
+ } else {
103
+ TableHeaderComponent (
104
+ headerTableTitles = headerTableTitles,
105
+ headerTitlesBorderColor = headerTitlesBorderColor,
106
+ headerTitlesTextStyle = headerTitlesTextStyle,
107
+ headerTitlesBackGroundColor = headerTitlesBackGroundColor,
108
+ contentAlignment = contentAlignment,
109
+ textAlign = textAlign,
110
+ tablePadding = tablePadding,
111
+ dividerThickness = dividerThickness,
112
+ columnToIndexIncreaseWidth = columnToIndexIncreaseWidth,
113
+ )
114
+ }
83
115
}
84
116
85
117
data.forEachIndexed { index, data ->
@@ -94,13 +126,31 @@ inline fun <reified T : Any> BeeTablesCompose(
94
126
tableRowColors[1 ]
95
127
}
96
128
97
- TableRowComponent (
98
- data = rowData,
99
- rowBorderColor = rowBorderColor,
100
- rowBorderWidth = rowBorderWidth,
101
- rowTextStyle = rowTextStyle,
102
- rowBackGroundColor = tableRowBackgroundColor,
103
- )
129
+ if (disableVerticalDividers) {
130
+ TableRowComponentWithoutDividers (
131
+ data = rowData,
132
+ rowTextStyle = rowTextStyle,
133
+ rowBackGroundColor = tableRowBackgroundColor,
134
+ dividerThickness = dividerThickness,
135
+ horizontalDividerColor = horizontalDividerColor,
136
+ contentAlignment = contentAlignment,
137
+ textAlign = textAlign,
138
+ tablePadding = tablePadding,
139
+ columnToIndexIncreaseWidth = columnToIndexIncreaseWidth,
140
+ )
141
+ } else {
142
+ TableRowComponent (
143
+ data = rowData,
144
+ rowBorderColor = rowBorderColor,
145
+ dividerThickness = dividerThickness,
146
+ rowTextStyle = rowTextStyle,
147
+ rowBackGroundColor = tableRowBackgroundColor,
148
+ contentAlignment = contentAlignment,
149
+ textAlign = textAlign,
150
+ tablePadding = tablePadding,
151
+ columnToIndexIncreaseWidth = columnToIndexIncreaseWidth,
152
+ )
153
+ }
104
154
}
105
155
}
106
156
}
0 commit comments