├── .fleet └── receipt.json ├── .github └── workflows │ └── publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── iosApp ├── iosApp.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── iosApp │ ├── ContentView.swift │ ├── Info.plist │ ├── iosApp.entitlements │ └── iosAppApp.swift ├── lib ├── build.gradle.kts └── src │ ├── androidMain │ ├── AndroidManifest.xml │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── Util.android.kt │ ├── commonMain │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ ├── ColumnComposables.kt │ │ ├── ColumnSpec.kt │ │ ├── DropdownPicker.kt │ │ ├── PaginationBar.kt │ │ ├── PlatformUtil.kt │ │ ├── Table.kt │ │ ├── Util.kt │ │ ├── filter │ │ ├── CheckboxFilterModal.kt │ │ ├── ColumnFilter.kt │ │ ├── DateFilterModal.kt │ │ ├── DoubleFilterModal.kt │ │ ├── DropdownFilterModal.kt │ │ ├── FilterBar.kt │ │ ├── IntFilterModal.kt │ │ └── TextFilterModal.kt │ │ └── icons │ │ ├── ArrowDownward.kt │ │ ├── ArrowUpward.kt │ │ ├── ChevronLeft.kt │ │ ├── ChevronRight.kt │ │ ├── Close.kt │ │ ├── DataTableIcons.kt │ │ ├── DateRange.kt │ │ ├── FilterList.kt │ │ ├── FirstPage.kt │ │ └── LastPage.kt │ ├── desktopMain │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── Util.desktop.kt │ ├── iosMain │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── Util.ios.kt │ └── wasmJsMain │ ├── kotlin │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── Util.wasm.kt │ └── resources │ ├── index.html │ └── styles.css ├── sample ├── build.gradle.kts └── src │ ├── androidMain │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── io │ │ │ └── github │ │ │ └── aleksandar_stefanovic │ │ │ └── composematerialdatatable │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ └── strings.xml │ ├── commonMain │ ├── composeResources │ │ └── drawable │ │ │ ├── close.xml │ │ │ ├── compose-multiplatform.xml │ │ │ └── filter-list.xml │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── App.kt │ ├── desktopMain │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── main.kt │ ├── iosMain │ └── kotlin │ │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── MainViewController.kt │ └── wasmJsMain │ ├── kotlin │ └── io │ │ └── github │ │ └── aleksandar_stefanovic │ │ └── composematerialdatatable │ │ └── main.kt │ └── resources │ ├── index.html │ └── styles.css └── settings.gradle.kts /.fleet/receipt.json: -------------------------------------------------------------------------------- 1 | // Project generated by Kotlin Multiplatform Wizard 2 | { 3 | "spec": { 4 | "template_id": "kmt", 5 | "targets": { 6 | "android": { 7 | "ui": [ 8 | "compose" 9 | ] 10 | }, 11 | "desktop": { 12 | "ui": [ 13 | "compose" 14 | ] 15 | }, 16 | "web": { 17 | "ui": [ 18 | "compose" 19 | ] 20 | } 21 | } 22 | }, 23 | "timestamp": "2025-01-19T22:01:28.940580494Z" 24 | } -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # .github/workflows/publish.yml 2 | 3 | name: Publish 4 | on: 5 | release: 6 | types: [released, prereleased] 7 | jobs: 8 | publish: 9 | name: Release build and publish 10 | runs-on: macOS-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v4 14 | - name: Set up JDK 21 15 | uses: actions/setup-java@v4 16 | with: 17 | distribution: 'zulu' 18 | java-version: 21 19 | - name: Publish to MavenCentral 20 | run: ./gradlew :lib:publishToMavenCentral --no-configuration-cache 21 | env: 22 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} 23 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} 24 | ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} 25 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} 26 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .kotlin 3 | .gradle 4 | **/build/ 5 | xcuserdata 6 | !src/**/build/ 7 | local.properties 8 | .idea 9 | .DS_Store 10 | captures 11 | .externalNativeBuild 12 | .cxx 13 | *.xcodeproj/* 14 | !*.xcodeproj/project.pbxproj 15 | !*.xcodeproj/xcshareddata/ 16 | !*.xcodeproj/project.xcworkspace/ 17 | !*.xcworkspace/contents.xcworkspacedata 18 | **/xcshareddata/WorkspaceSettings.xcsettings 19 | key.gpg 20 | kotlin-js-store/yarn.lock 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Aleksandar Stefanović 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![maven central version](https://img.shields.io/maven-central/v/io.github.aleksandar-stefanovic/composematerialdatatable) 2 | 3 | ### A Kotlin & Compose Multiplatform implementation of the [Material 2 Data Table](https://m2.material.io/components/data-tables). 4 | 5 | ![image](https://github.com/user-attachments/assets/3ff22543-afcd-43c6-887f-b4e5d8c58b9d) 6 | 7 | # Setup 8 | ## Using `libs.versions.toml` 9 | To add the dependency to your Kotlin Multiplatform project, open the `build.gradle.kts` of your shared module, then 10 | ```kts 11 | kotlin { 12 | sourceSets { 13 | commonMain.dependencies { 14 | implementation(libs.composematerialdatatable) 15 | } 16 | } 17 | } 18 | ``` 19 | and, in your `libs.versions.toml`, add: 20 | ```toml 21 | composematerialdatatable = "1.2.1" 22 | 23 | [libraries] 24 | composematerialdatatable = { module = "io.github.aleksandar-stefanovic:composematerialdatatable", version.ref = "composematerialdatatable" } 25 | ``` 26 | 27 | ## Using direct dependency notation 28 | 29 | ```kts 30 | kotlin { 31 | sourceSets { 32 | commonMain.dependencies { 33 | implementation("io.github.aleksandar-stefanovic:composematerialdatatable:1.2.1") 34 | } 35 | } 36 | } 37 | ``` 38 | 39 | # Features 40 | - Column width settings 41 | - Fixed — the column with use the specified width 42 | - Wrap Content — the column will spread to the intrinsic width of the content 43 | - Flex — the column will use remaining available space, split across all Flex columns by weight 44 | - Sorting — click on the table header to toggle between sorting ascending, descending, and resetting 45 | - Column types 46 | - String 47 | - Int 48 | - Double 49 | - Date 50 | - Dropdown (specific set of values) 51 | - Checkbox (Boolean) 52 | - Column aligning 53 | - Text selection (works but selecting multiple cells at once just concatenates them without whitespace at the moment) 54 | - Toggleable selection column (first column with tri-state checkbox header and checkbox cells, which emits events on interaction) 55 | - Filtering 56 | - Client-based pagination 57 | - Horizontal and vertical scrolling 58 | 59 | For the planned features, see [Issues](https://github.com/aleksandar-stefanovic/compose-material-data-table/issues). 60 | 61 | ## Supported platforms 62 | Right now, it is tested and working on: 63 | - Desktop 64 | - Android 65 | - WASM (with the limitation of not having number formatting) 66 | - iOS 67 | 68 | # Example 69 | Gradle submodule `sample` contains a working example of the `Table` implementation, see [Sample App.kt](https://github.com/aleksandar-stefanovic/compose-material-data-table/blob/main/sample/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/App.kt). 70 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | // this is necessary to avoid the plugins to be loaded multiple times 3 | // in each subproject's classloader 4 | alias(libs.plugins.androidApplication) apply false 5 | alias(libs.plugins.androidLibrary) apply false 6 | alias(libs.plugins.composeMultiplatform) apply false 7 | alias(libs.plugins.composeCompiler) apply false 8 | alias(libs.plugins.kotlinMultiplatform) apply false 9 | // Recommended by https://github.com/kotlin-hands-on/fibonacci 10 | alias(libs.plugins.vanniktechMavenPublish) 11 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | #Kotlin 2 | kotlin.code.style=official 3 | kotlin.daemon.jvmargs=-Xmx2048M 4 | 5 | #Gradle 6 | org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 7 | 8 | #Android 9 | android.nonTransitiveRClass=true 10 | android.useAndroidX=true -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | agp = "8.9.1" 3 | android-compileSdk = "35" 4 | android-minSdk = "21" 5 | android-targetSdk = "35" 6 | androidx-activityCompose = "1.10.1" 7 | androidx-lifecycle = "2.8.4" 8 | compose-multiplatform = "1.7.0" 9 | kotlin = "2.1.0" 10 | kotlinx-coroutines = "1.10.1" 11 | kotlinxDatetime = "0.6.1" 12 | vanniktech-maven-publish = "0.30.0" 13 | 14 | [libraries] 15 | androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } 16 | androidx-lifecycle-viewmodel = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel", version.ref = "androidx-lifecycle" } 17 | androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" } 18 | kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } 19 | kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" } 20 | 21 | [plugins] 22 | androidApplication = { id = "com.android.application", version.ref = "agp" } 23 | androidLibrary = { id = "com.android.library", version.ref = "agp" } 24 | composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" } 25 | composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } 26 | kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } 27 | vanniktechMavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-maven-publish" } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s 90 | ' "$PWD" ) || exit 91 | 92 | # Use the maximum available, or set MAX_FD != -1 to use that value. 93 | MAX_FD=maximum 94 | 95 | warn () { 96 | echo "$*" 97 | } >&2 98 | 99 | die () { 100 | echo 101 | echo "$*" 102 | echo 103 | exit 1 104 | } >&2 105 | 106 | # OS specific support (must be 'true' or 'false'). 107 | cygwin=false 108 | msys=false 109 | darwin=false 110 | nonstop=false 111 | case "$( uname )" in #( 112 | CYGWIN* ) cygwin=true ;; #( 113 | Darwin* ) darwin=true ;; #( 114 | MSYS* | MINGW* ) msys=true ;; #( 115 | NONSTOP* ) nonstop=true ;; 116 | esac 117 | 118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 119 | 120 | 121 | # Determine the Java command to use to start the JVM. 122 | if [ -n "$JAVA_HOME" ] ; then 123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 124 | # IBM's JDK on AIX uses strange locations for the executables 125 | JAVACMD=$JAVA_HOME/jre/sh/java 126 | else 127 | JAVACMD=$JAVA_HOME/bin/java 128 | fi 129 | if [ ! -x "$JAVACMD" ] ; then 130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 131 | 132 | Please set the JAVA_HOME variable in your environment to match the 133 | location of your Java installation." 134 | fi 135 | else 136 | JAVACMD=java 137 | if ! command -v java >/dev/null 2>&1 138 | then 139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 140 | 141 | Please set the JAVA_HOME variable in your environment to match the 142 | location of your Java installation." 143 | fi 144 | fi 145 | 146 | # Increase the maximum file descriptors if we can. 147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 148 | case $MAX_FD in #( 149 | max*) 150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 151 | # shellcheck disable=SC2039,SC3045 152 | MAX_FD=$( ulimit -H -n ) || 153 | warn "Could not query maximum file descriptor limit" 154 | esac 155 | case $MAX_FD in #( 156 | '' | soft) :;; #( 157 | *) 158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 159 | # shellcheck disable=SC2039,SC3045 160 | ulimit -n "$MAX_FD" || 161 | warn "Could not set maximum file descriptor limit to $MAX_FD" 162 | esac 163 | fi 164 | 165 | # Collect all arguments for the java command, stacking in reverse order: 166 | # * args from the command line 167 | # * the main class name 168 | # * -classpath 169 | # * -D...appname settings 170 | # * --module-path (only if needed) 171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 172 | 173 | # For Cygwin or MSYS, switch paths to Windows format before running java 174 | if "$cygwin" || "$msys" ; then 175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 177 | 178 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 179 | 180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 181 | for arg do 182 | if 183 | case $arg in #( 184 | -*) false ;; # don't mess with options #( 185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 186 | [ -e "$t" ] ;; #( 187 | *) false ;; 188 | esac 189 | then 190 | arg=$( cygpath --path --ignore --mixed "$arg" ) 191 | fi 192 | # Roll the args list around exactly as many times as the number of 193 | # args, so each arg winds up back in the position where it started, but 194 | # possibly modified. 195 | # 196 | # NB: a `for` loop captures its iteration list before it begins, so 197 | # changing the positional parameters here affects neither the number of 198 | # iterations, nor the values presented in `arg`. 199 | shift # remove old arg 200 | set -- "$@" "$arg" # push replacement arg 201 | done 202 | fi 203 | 204 | 205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 207 | 208 | # Collect all arguments for the java command: 209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 210 | # and any embedded shellness will be escaped. 211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 212 | # treated as '${Hostname}' itself on the command line. 213 | 214 | set -- \ 215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 216 | -classpath "$CLASSPATH" \ 217 | org.gradle.wrapper.GradleWrapperMain \ 218 | "$@" 219 | 220 | # Stop when "xargs" is not available. 221 | if ! command -v xargs >/dev/null 2>&1 222 | then 223 | die "xargs is not available" 224 | fi 225 | 226 | # Use "xargs" to parse quoted args. 227 | # 228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 229 | # 230 | # In Bash we could simply go: 231 | # 232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 233 | # set -- "${ARGS[@]}" "$@" 234 | # 235 | # but POSIX shell has neither arrays nor command substitution, so instead we 236 | # post-process each arg (as a line of input to sed) to backslash-escape any 237 | # character that might be a shell metacharacter, then use eval to reverse 238 | # that process (while maintaining the separation between arguments), and wrap 239 | # the whole thing up as a single "set" statement. 240 | # 241 | # This will of course break if any of these variables contains a newline or 242 | # an unmatched quote. 243 | # 244 | 245 | eval "set -- $( 246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 247 | xargs -n1 | 248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 249 | tr '\n' ' ' 250 | )" '"$@"' 251 | 252 | exec "$JAVACMD" "$@" 253 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /iosApp/iosApp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 77; 7 | objects = { 8 | 9 | /* Begin PBXFileReference section */ 10 | 124701562D88B05200A84B78 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 11 | /* End PBXFileReference section */ 12 | 13 | /* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ 14 | 124701882D88B5AF00A84B78 /* Exceptions for "iosApp" folder in "iosApp" target */ = { 15 | isa = PBXFileSystemSynchronizedBuildFileExceptionSet; 16 | membershipExceptions = ( 17 | Info.plist, 18 | ); 19 | target = 124701552D88B05200A84B78 /* iosApp */; 20 | }; 21 | /* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ 22 | 23 | /* Begin PBXFileSystemSynchronizedRootGroup section */ 24 | 124701582D88B05200A84B78 /* iosApp */ = { 25 | isa = PBXFileSystemSynchronizedRootGroup; 26 | exceptions = ( 27 | 124701882D88B5AF00A84B78 /* Exceptions for "iosApp" folder in "iosApp" target */, 28 | ); 29 | path = iosApp; 30 | sourceTree = ""; 31 | }; 32 | /* End PBXFileSystemSynchronizedRootGroup section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | 124701532D88B05200A84B78 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 1247014D2D88B05200A84B78 = { 46 | isa = PBXGroup; 47 | children = ( 48 | 124701582D88B05200A84B78 /* iosApp */, 49 | 124701572D88B05200A84B78 /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | 124701572D88B05200A84B78 /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 124701562D88B05200A84B78 /* iosApp.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | /* End PBXGroup section */ 62 | 63 | /* Begin PBXNativeTarget section */ 64 | 124701552D88B05200A84B78 /* iosApp */ = { 65 | isa = PBXNativeTarget; 66 | buildConfigurationList = 124701652D88B05300A84B78 /* Build configuration list for PBXNativeTarget "iosApp" */; 67 | buildPhases = ( 68 | 124701682D88B0A300A84B78 /* Compile Kotlin Framework */, 69 | 124701522D88B05200A84B78 /* Sources */, 70 | 124701532D88B05200A84B78 /* Frameworks */, 71 | 124701542D88B05200A84B78 /* Resources */, 72 | ); 73 | buildRules = ( 74 | ); 75 | dependencies = ( 76 | ); 77 | fileSystemSynchronizedGroups = ( 78 | 124701582D88B05200A84B78 /* iosApp */, 79 | ); 80 | name = iosApp; 81 | packageProductDependencies = ( 82 | ); 83 | productName = iosApp; 84 | productReference = 124701562D88B05200A84B78 /* iosApp.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 1247014E2D88B05200A84B78 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | BuildIndependentTargetsInParallel = 1; 94 | LastSwiftUpdateCheck = 1620; 95 | LastUpgradeCheck = 1620; 96 | TargetAttributes = { 97 | 124701552D88B05200A84B78 = { 98 | CreatedOnToolsVersion = 16.2; 99 | }; 100 | }; 101 | }; 102 | buildConfigurationList = 124701512D88B05200A84B78 /* Build configuration list for PBXProject "iosApp" */; 103 | developmentRegion = en; 104 | hasScannedForEncodings = 0; 105 | knownRegions = ( 106 | en, 107 | Base, 108 | ); 109 | mainGroup = 1247014D2D88B05200A84B78; 110 | minimizedProjectReferenceProxies = 1; 111 | preferredProjectObjectVersion = 77; 112 | productRefGroup = 124701572D88B05200A84B78 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 124701552D88B05200A84B78 /* iosApp */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 124701542D88B05200A84B78 /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | ); 127 | runOnlyForDeploymentPostprocessing = 0; 128 | }; 129 | /* End PBXResourcesBuildPhase section */ 130 | 131 | /* Begin PBXShellScriptBuildPhase section */ 132 | 124701682D88B0A300A84B78 /* Compile Kotlin Framework */ = { 133 | isa = PBXShellScriptBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | ); 137 | inputFileListPaths = ( 138 | ); 139 | inputPaths = ( 140 | ); 141 | name = "Compile Kotlin Framework"; 142 | outputFileListPaths = ( 143 | ); 144 | outputPaths = ( 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | shellPath = /bin/sh; 148 | shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/../\"\n./gradlew :sample:embedAndSignAppleFrameworkForXcode\n\n"; 149 | }; 150 | /* End PBXShellScriptBuildPhase section */ 151 | 152 | /* Begin PBXSourcesBuildPhase section */ 153 | 124701522D88B05200A84B78 /* Sources */ = { 154 | isa = PBXSourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXSourcesBuildPhase section */ 161 | 162 | /* Begin XCBuildConfiguration section */ 163 | 124701632D88B05300A84B78 /* Debug */ = { 164 | isa = XCBuildConfiguration; 165 | buildSettings = { 166 | ALWAYS_SEARCH_USER_PATHS = NO; 167 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 168 | CLANG_ANALYZER_NONNULL = YES; 169 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 170 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 171 | CLANG_ENABLE_MODULES = YES; 172 | CLANG_ENABLE_OBJC_ARC = YES; 173 | CLANG_ENABLE_OBJC_WEAK = YES; 174 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 175 | CLANG_WARN_BOOL_CONVERSION = YES; 176 | CLANG_WARN_COMMA = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 179 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 180 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 181 | CLANG_WARN_EMPTY_BODY = YES; 182 | CLANG_WARN_ENUM_CONVERSION = YES; 183 | CLANG_WARN_INFINITE_RECURSION = YES; 184 | CLANG_WARN_INT_CONVERSION = YES; 185 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 186 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 187 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 190 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 191 | CLANG_WARN_STRICT_PROTOTYPES = YES; 192 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 193 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | ENABLE_USER_SCRIPT_SANDBOXING = NO; 201 | GCC_C_LANGUAGE_STANDARD = gnu17; 202 | GCC_DYNAMIC_NO_PIC = NO; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_OPTIMIZATION_LEVEL = 0; 205 | GCC_PREPROCESSOR_DEFINITIONS = ( 206 | "DEBUG=1", 207 | "$(inherited)", 208 | ); 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 216 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 217 | MTL_FAST_MATH = YES; 218 | ONLY_ACTIVE_ARCH = YES; 219 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 220 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 221 | }; 222 | name = Debug; 223 | }; 224 | 124701642D88B05300A84B78 /* Release */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_ENABLE_OBJC_WEAK = YES; 235 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 236 | CLANG_WARN_BOOL_CONVERSION = YES; 237 | CLANG_WARN_COMMA = YES; 238 | CLANG_WARN_CONSTANT_CONVERSION = YES; 239 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 240 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 241 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 242 | CLANG_WARN_EMPTY_BODY = YES; 243 | CLANG_WARN_ENUM_CONVERSION = YES; 244 | CLANG_WARN_INFINITE_RECURSION = YES; 245 | CLANG_WARN_INT_CONVERSION = YES; 246 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 247 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 248 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 251 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 252 | CLANG_WARN_STRICT_PROTOTYPES = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | ENABLE_USER_SCRIPT_SANDBOXING = NO; 262 | GCC_C_LANGUAGE_STANDARD = gnu17; 263 | GCC_NO_COMMON_BLOCKS = YES; 264 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 265 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 266 | GCC_WARN_UNDECLARED_SELECTOR = YES; 267 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 268 | GCC_WARN_UNUSED_FUNCTION = YES; 269 | GCC_WARN_UNUSED_VARIABLE = YES; 270 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 271 | MTL_ENABLE_DEBUG_INFO = NO; 272 | MTL_FAST_MATH = YES; 273 | SWIFT_COMPILATION_MODE = wholemodule; 274 | }; 275 | name = Release; 276 | }; 277 | 124701662D88B05300A84B78 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 282 | CODE_SIGN_ENTITLEMENTS = iosApp/iosApp.entitlements; 283 | CODE_SIGN_STYLE = Automatic; 284 | CURRENT_PROJECT_VERSION = 1; 285 | DEVELOPMENT_ASSET_PATHS = ""; 286 | ENABLE_PREVIEWS = YES; 287 | ENABLE_USER_SCRIPT_SANDBOXING = NO; 288 | GENERATE_INFOPLIST_FILE = YES; 289 | INFOPLIST_FILE = iosApp/Info.plist; 290 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; 291 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; 292 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; 293 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; 294 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; 295 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; 296 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; 297 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; 298 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 299 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 300 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 301 | LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; 302 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; 303 | MACOSX_DEPLOYMENT_TARGET = 15.2; 304 | MARKETING_VERSION = 1.0; 305 | PRODUCT_BUNDLE_IDENTIFIER = "io.github.aleksandar-stefanovic.iosApp"; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | SDKROOT = auto; 308 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 309 | SUPPORTS_MACCATALYST = NO; 310 | SWIFT_EMIT_LOC_STRINGS = YES; 311 | SWIFT_VERSION = 5.0; 312 | TARGETED_DEVICE_FAMILY = "1,2"; 313 | XROS_DEPLOYMENT_TARGET = 2.2; 314 | }; 315 | name = Debug; 316 | }; 317 | 124701672D88B05300A84B78 /* Release */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 321 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 322 | CODE_SIGN_ENTITLEMENTS = iosApp/iosApp.entitlements; 323 | CODE_SIGN_STYLE = Automatic; 324 | CURRENT_PROJECT_VERSION = 1; 325 | DEVELOPMENT_ASSET_PATHS = ""; 326 | ENABLE_PREVIEWS = YES; 327 | ENABLE_USER_SCRIPT_SANDBOXING = NO; 328 | GENERATE_INFOPLIST_FILE = YES; 329 | INFOPLIST_FILE = iosApp/Info.plist; 330 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; 331 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; 332 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; 333 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; 334 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; 335 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; 336 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; 337 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; 338 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 339 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 340 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 341 | LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; 342 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; 343 | MACOSX_DEPLOYMENT_TARGET = 15.2; 344 | MARKETING_VERSION = 1.0; 345 | PRODUCT_BUNDLE_IDENTIFIER = "io.github.aleksandar-stefanovic.iosApp"; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SDKROOT = auto; 348 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 349 | SUPPORTS_MACCATALYST = NO; 350 | SWIFT_EMIT_LOC_STRINGS = YES; 351 | SWIFT_VERSION = 5.0; 352 | TARGETED_DEVICE_FAMILY = "1,2"; 353 | XROS_DEPLOYMENT_TARGET = 2.2; 354 | }; 355 | name = Release; 356 | }; 357 | /* End XCBuildConfiguration section */ 358 | 359 | /* Begin XCConfigurationList section */ 360 | 124701512D88B05200A84B78 /* Build configuration list for PBXProject "iosApp" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | 124701632D88B05300A84B78 /* Debug */, 364 | 124701642D88B05300A84B78 /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | 124701652D88B05300A84B78 /* Build configuration list for PBXNativeTarget "iosApp" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | 124701662D88B05300A84B78 /* Debug */, 373 | 124701672D88B05300A84B78 /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | /* End XCConfigurationList section */ 379 | }; 380 | rootObject = 1247014E2D88B05200A84B78 /* Project object */; 381 | } 382 | -------------------------------------------------------------------------------- /iosApp/iosApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosApp/iosApp/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import ComposeMaterialDataTable 3 | 4 | struct ComposeView: UIViewControllerRepresentable { 5 | func makeUIViewController(context: Context) -> UIViewController { 6 | MainViewControllerKt.MainViewController() 7 | } 8 | 9 | func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} 10 | } 11 | 12 | struct ContentView: View { 13 | var body: some View { 14 | ComposeView() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /iosApp/iosApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CADisableMinimumFrameDurationOnPhone 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /iosApp/iosApp/iosApp.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /iosApp/iosApp/iosAppApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct iosAppApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.vanniktech.maven.publish.SonatypeHost 2 | import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl 3 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 4 | import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig 5 | 6 | plugins { 7 | alias(libs.plugins.kotlinMultiplatform) 8 | alias(libs.plugins.androidLibrary) 9 | alias(libs.plugins.composeMultiplatform) 10 | alias(libs.plugins.composeCompiler) 11 | // Recommended by https://github.com/kotlin-hands-on/fibonacci 12 | alias(libs.plugins.vanniktechMavenPublish) 13 | } 14 | 15 | version = "1.2.1" 16 | group = "io.github.aleksandar-stefanovic" 17 | 18 | kotlin { 19 | 20 | // Explicit API compiler flag, since this is a library. Switch from Warning to Strict at some point 21 | explicitApiWarning() 22 | 23 | androidTarget { 24 | compilerOptions { 25 | jvmTarget.set(JvmTarget.JVM_11) 26 | } 27 | } 28 | 29 | iosX64() 30 | iosArm64() 31 | iosSimulatorArm64() 32 | 33 | jvm("desktop") 34 | 35 | @OptIn(ExperimentalWasmDsl::class) 36 | wasmJs { 37 | moduleName = "lib" 38 | browser { 39 | val rootDirPath = project.rootDir.path 40 | val projectDirPath = project.projectDir.path 41 | commonWebpackConfig { 42 | outputFileName = "lib.js" 43 | devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { 44 | static = (static ?: mutableListOf()).apply { 45 | // Serve sources to debug inside browser 46 | add(rootDirPath) 47 | add(projectDirPath) 48 | } 49 | } 50 | } 51 | } 52 | } 53 | 54 | sourceSets { 55 | val desktopMain by getting 56 | 57 | commonMain.dependencies { 58 | implementation(compose.runtime) 59 | implementation(compose.foundation) 60 | implementation(compose.material) 61 | implementation(compose.material3) 62 | implementation(compose.ui) 63 | implementation(libs.kotlinx.datetime) 64 | } 65 | desktopMain.dependencies { 66 | implementation(compose.desktop.currentOs) 67 | } 68 | } 69 | } 70 | 71 | android { 72 | namespace = "io.github.aleksandar_stefanovic.composematerialdatatable" 73 | compileSdk = libs.versions.android.compileSdk.get().toInt() 74 | defaultConfig { 75 | minSdk = libs.versions.android.minSdk.get().toInt() 76 | } 77 | packaging { 78 | resources { 79 | excludes += "/META-INF/{AL2.0,LGPL2.1}" 80 | } 81 | } 82 | buildTypes { 83 | getByName("release") { 84 | isMinifyEnabled = true 85 | } 86 | } 87 | compileOptions { 88 | sourceCompatibility = JavaVersion.VERSION_11 89 | targetCompatibility = JavaVersion.VERSION_11 90 | } 91 | } 92 | 93 | mavenPublishing { 94 | publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 95 | 96 | signAllPublications() 97 | 98 | coordinates(group.toString(), "composematerialdatatable", version.toString()) 99 | 100 | pom { 101 | name = "Compose Material Data Table" 102 | description = "A Kotlin Multiplatform and Jetpack Compose Multiplatform compliant implementation of the Material 2 Data Table." 103 | inceptionYear = "2025" 104 | url = "https://github.com/aleksandar-stefanovic/compose-material-data-table" 105 | licenses { 106 | license { 107 | name = "MIT License" 108 | url = "http://www.opensource.org/licenses/mit-license.php" 109 | distribution = "http://www.opensource.org/licenses/mit-license.php" 110 | } 111 | } 112 | developers { 113 | developer { 114 | id = "aleksandar-stefanovic" 115 | name = "Aleksandar Stefanović" 116 | url = "https://github.com/aleksandar-stefanovic" 117 | } 118 | } 119 | scm { 120 | url = "https://github.com/aleksandar-stefanovic/compose-material-data-table" 121 | connection = "scm:git:git://github.com/aleksandar-stefanovic/compose-material-data-table.git" 122 | developerConnection = "scm:git:ssh://git@github.com/aleksandar-stefanovic/compose-material-data-table.git" 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /lib/src/androidMain/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /lib/src/androidMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Util.android.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | actual fun String.format(int: Int): String = String.format(this, int) 4 | 5 | actual fun String.format(float: Float): String = String.format(this, float) 6 | 7 | actual fun String.format(double: Double): String = String.format(this, double) -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/ColumnComposables.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.background 5 | import androidx.compose.foundation.clickable 6 | import androidx.compose.foundation.hoverable 7 | import androidx.compose.foundation.interaction.MutableInteractionSource 8 | import androidx.compose.foundation.interaction.collectIsHoveredAsState 9 | import androidx.compose.foundation.layout.Arrangement 10 | import androidx.compose.foundation.layout.Box 11 | import androidx.compose.foundation.layout.Row 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.material.Checkbox 14 | import androidx.compose.material.DropdownMenu 15 | import androidx.compose.material.DropdownMenuItem 16 | import androidx.compose.material.Text 17 | import androidx.compose.material.TriStateCheckbox 18 | import androidx.compose.runtime.Composable 19 | import androidx.compose.runtime.getValue 20 | import androidx.compose.runtime.mutableStateOf 21 | import androidx.compose.runtime.remember 22 | import androidx.compose.runtime.setValue 23 | import androidx.compose.ui.Alignment 24 | import androidx.compose.ui.Modifier 25 | import androidx.compose.ui.draw.alpha 26 | import androidx.compose.ui.graphics.Color 27 | import androidx.compose.ui.state.ToggleableState 28 | import androidx.compose.ui.text.font.FontWeight 29 | import androidx.compose.ui.text.style.TextAlign 30 | import androidx.compose.ui.text.style.TextOverflow 31 | import androidx.compose.ui.unit.dp 32 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.ArrowDownward 33 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.ArrowUpward 34 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.DataTableIcons 35 | import kotlinx.datetime.LocalDate 36 | import kotlinx.datetime.format.DateTimeFormat 37 | 38 | @Composable 39 | internal fun TextHeader( 40 | headerText: String, 41 | horizontalArrangement: Arrangement.Horizontal, 42 | sortOrder: SortOrder? = null, 43 | onClick: () -> Unit 44 | ) { 45 | Row( 46 | Modifier.background(Color.White).clickable { onClick() } 47 | .padding(16.dp), 48 | horizontalArrangement, 49 | Alignment.CenterVertically 50 | ) { 51 | if (horizontalArrangement == Arrangement.Start) { 52 | Text( 53 | headerText, 54 | fontWeight = FontWeight.SemiBold, 55 | overflow = TextOverflow.Ellipsis, 56 | maxLines = 1 57 | ) 58 | } 59 | 60 | when (sortOrder) { 61 | SortOrder.ASC -> Image( 62 | imageVector = DataTableIcons.ArrowUpward, 63 | contentDescription = "Ascending sorting", 64 | modifier = Modifier.alpha(0.5f) 65 | ) 66 | SortOrder.DESC -> Image( 67 | imageVector = DataTableIcons.ArrowDownward, 68 | contentDescription = "Descending sorting", 69 | modifier = Modifier.alpha(0.5f) 70 | ) 71 | null -> { 72 | // Keep an invisible icon to reserve column space 73 | Image( 74 | imageVector = DataTableIcons.ArrowUpward, 75 | contentDescription = "Ascending sorting", 76 | modifier = Modifier.alpha(0f) 77 | ) 78 | } 79 | } 80 | 81 | if (horizontalArrangement == Arrangement.End) { 82 | Text( 83 | headerText, 84 | fontWeight = FontWeight.SemiBold, 85 | overflow = TextOverflow.Ellipsis, 86 | maxLines = 1 87 | ) 88 | } 89 | } 90 | } 91 | 92 | @Composable 93 | internal fun CheckboxHeader(state: ToggleableState, onClick: () -> Unit) { 94 | TriStateCheckbox(state, onClick, Modifier.background(Color.White)) 95 | } 96 | 97 | // Approximation of what the color is when the surface is white and the hovered element is clickable 98 | // Ideally should be a Material token, but this will suffice for now 99 | private val hoverColor = Color(0xfff3f3f3) 100 | 101 | @Composable 102 | internal fun TextCell(text: String, textAlign: TextAlign, interactionSource: MutableInteractionSource) { 103 | 104 | val isHovered by interactionSource.collectIsHoveredAsState() 105 | val backgroundColor = if (isHovered) hoverColor else Color.White 106 | 107 | Text( 108 | text, 109 | Modifier.hoverable(interactionSource).background(backgroundColor).padding(16.dp), 110 | textAlign = textAlign, 111 | overflow = TextOverflow.Ellipsis, 112 | maxLines = 1 113 | ) 114 | } 115 | 116 | @Composable 117 | internal fun IntCell(int: Int, numberFormat: String? = null, textAlign: TextAlign, interactionSource: MutableInteractionSource) { 118 | 119 | val isHovered by interactionSource.collectIsHoveredAsState() 120 | val backgroundColor = if (isHovered) hoverColor else Color.White 121 | 122 | val stringValue = numberFormat?.format(int) ?: int.toString() 123 | Text( 124 | stringValue, 125 | Modifier.hoverable(interactionSource).background(backgroundColor).padding(16.dp), 126 | textAlign = textAlign, 127 | overflow = TextOverflow.Ellipsis, 128 | maxLines = 1 129 | ) 130 | } 131 | 132 | @Composable 133 | internal fun DoubleCell(double: Double, numberFormat: String? = null, textAlign: TextAlign, interactionSource: MutableInteractionSource) { 134 | 135 | val isHovered by interactionSource.collectIsHoveredAsState() 136 | val backgroundColor = if (isHovered) hoverColor else Color.White 137 | 138 | Text( 139 | numberFormat?.format(double) ?: double.toString(), 140 | Modifier.hoverable(interactionSource).background(backgroundColor).padding(16.dp), 141 | textAlign = textAlign, 142 | overflow = TextOverflow.Ellipsis, 143 | maxLines = 1 144 | ) 145 | } 146 | 147 | @Composable 148 | internal fun DateCell(date: LocalDate, dateFormat: DateTimeFormat, textAlign: TextAlign, interactionSource: MutableInteractionSource) { 149 | 150 | val isHovered by interactionSource.collectIsHoveredAsState() 151 | val backgroundColor = if (isHovered) hoverColor else Color.White 152 | 153 | Text( 154 | dateFormat.format(date), 155 | Modifier.hoverable(interactionSource).background(backgroundColor).padding(16.dp), 156 | textAlign = textAlign, 157 | overflow = TextOverflow.Ellipsis, 158 | maxLines = 1 159 | ) 160 | } 161 | 162 | @Composable 163 | internal fun CheckboxCell(selected: Boolean, interactionSource: MutableInteractionSource, onClick: (Boolean) -> Unit) { 164 | 165 | val isHovered by interactionSource.collectIsHoveredAsState() 166 | val backgroundColor = if (isHovered) hoverColor else Color.White 167 | 168 | Checkbox( 169 | selected, 170 | onClick, 171 | Modifier.hoverable(interactionSource).background(backgroundColor).padding(16.dp) 172 | ) 173 | } 174 | 175 | @Composable 176 | internal fun > DropdownCell( 177 | spec: DropdownColumnSpec, 178 | rowData: T, 179 | interactionSource: MutableInteractionSource 180 | ) { 181 | val isHovered by interactionSource.collectIsHoveredAsState() 182 | val backgroundColor = if (isHovered) hoverColor else Color.White 183 | 184 | var expanded by remember { mutableStateOf(false) } 185 | 186 | Box(Modifier.clickable { expanded = true }.hoverable(interactionSource).background(backgroundColor).padding(16.dp)) { 187 | Text(spec.valueFormatter(spec.valueSelector(rowData))) 188 | DropdownMenu(expanded, onDismissRequest = { expanded = false }) { 189 | spec.choices.forEach { choice -> 190 | DropdownMenuItem(onClick = { 191 | spec.onChoicePicked(choice) 192 | expanded = false 193 | }) { 194 | Text(spec.valueFormatter(choice)) 195 | } 196 | } 197 | } 198 | } 199 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/ColumnSpec.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.ui.unit.Dp 5 | import kotlinx.datetime.LocalDate 6 | import kotlinx.datetime.format.DateTimeFormat 7 | 8 | public sealed class WidthSetting { 9 | public class Static(public val width: Dp) : WidthSetting() 10 | public data object WrapContent : WidthSetting() 11 | public class Flex(public val weight: Float): WidthSetting() 12 | } 13 | 14 | public sealed class ColumnSpec>( 15 | public val headerName: String, 16 | public val widthSetting: WidthSetting, 17 | public val valueSelector: (T) -> S, 18 | public val horizontalArrangement: Arrangement.Horizontal = Arrangement.Start, 19 | ) { 20 | // Right now, the only reason to copy a ColumnSpec is to modify the widthSetting, thus it's the 21 | // only parameter of the function, so the code isn't overloaded with boilerplate code of 22 | // complete copying of an instance 23 | public abstract fun copy(widthSetting: WidthSetting): ColumnSpec 24 | } 25 | 26 | public class TextColumnSpec( 27 | headerName: String, 28 | widthSetting: WidthSetting, 29 | valueSelector: (T) -> String 30 | ) : ColumnSpec(headerName, widthSetting, valueSelector) { 31 | 32 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 33 | return TextColumnSpec(headerName, widthSetting, valueSelector) 34 | } 35 | } 36 | 37 | public class IntColumnSpec( 38 | headerName: String, 39 | widthSetting: WidthSetting, 40 | valueSelector: (T) -> Int, 41 | public val numberFormat: String? = null, 42 | ) : ColumnSpec(headerName, widthSetting, valueSelector, Arrangement.End) { 43 | 44 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 45 | return IntColumnSpec(headerName, widthSetting, valueSelector, numberFormat) 46 | } 47 | } 48 | 49 | public class DoubleColumnSpec( 50 | headerName: String, 51 | widthSetting: WidthSetting, 52 | valueSelector: (T) -> Double, 53 | public val numberFormat: String? = null, 54 | ): ColumnSpec(headerName, widthSetting, valueSelector, Arrangement.End) { 55 | 56 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 57 | return DoubleColumnSpec(headerName, widthSetting, valueSelector, numberFormat) 58 | } 59 | } 60 | 61 | 62 | public class DateColumnSpec( 63 | headerName: String, 64 | widthSetting: WidthSetting, 65 | valueSelector: (T) -> LocalDate, 66 | public val dateFormat: DateTimeFormat = LocalDate.Formats.ISO, 67 | ) : ColumnSpec(headerName, widthSetting, valueSelector, Arrangement.Start) { 68 | 69 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 70 | return DateColumnSpec(headerName, widthSetting, valueSelector, dateFormat) 71 | } 72 | 73 | } 74 | 75 | public class CheckboxColumnSpec( 76 | headerName: String, 77 | widthSetting: WidthSetting, 78 | valueSelector: (T) -> Boolean, 79 | ) : ColumnSpec(headerName, widthSetting, valueSelector) { 80 | 81 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 82 | return CheckboxColumnSpec(headerName, widthSetting, valueSelector) 83 | } 84 | } 85 | 86 | public class DropdownColumnSpec>( 87 | headerName: String, 88 | widthSetting: WidthSetting, 89 | valueSelector: (T) -> S, 90 | public val valueFormatter: (S) -> String = { it.toString() }, 91 | public val choices: List, 92 | public val onChoicePicked: (S) -> Unit 93 | ) : ColumnSpec(headerName, widthSetting, valueSelector) { 94 | 95 | override fun copy(widthSetting: WidthSetting): ColumnSpec { 96 | return DropdownColumnSpec(headerName, widthSetting, valueSelector, valueFormatter, choices, onChoicePicked) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/DropdownPicker.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.clickable 5 | import androidx.compose.foundation.layout.Box 6 | import androidx.compose.foundation.layout.Row 7 | import androidx.compose.foundation.layout.height 8 | import androidx.compose.material.DropdownMenu 9 | import androidx.compose.material.DropdownMenuItem 10 | import androidx.compose.material.Text 11 | import androidx.compose.material.icons.Icons 12 | import androidx.compose.material.icons.filled.ArrowDropDown 13 | import androidx.compose.runtime.Composable 14 | import androidx.compose.runtime.getValue 15 | import androidx.compose.runtime.mutableStateOf 16 | import androidx.compose.runtime.remember 17 | import androidx.compose.runtime.setValue 18 | import androidx.compose.ui.Alignment 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.unit.dp 21 | 22 | @Composable 23 | internal fun DropdownPicker( 24 | value: T, 25 | options: Iterable, 26 | valueFormatter: (T) -> String = { it.toString() }, 27 | onOptionPicked: (T) -> Unit 28 | ) { 29 | 30 | var showOptions by remember { mutableStateOf(false) } 31 | 32 | Box { 33 | Row(Modifier.height(48.dp).clickable { showOptions = true }, verticalAlignment = Alignment.CenterVertically) { 34 | Text(valueFormatter(value)) 35 | Image(Icons.Default.ArrowDropDown, "Dropdown") 36 | } 37 | 38 | DropdownMenu(showOptions, onDismissRequest = { showOptions = false }) { 39 | options.forEach { item -> 40 | DropdownMenuItem({ showOptions = false; onOptionPicked(item) }) { 41 | Text(valueFormatter(item)) 42 | } 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/PaginationBar.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.layout.Row 5 | import androidx.compose.foundation.layout.fillMaxHeight 6 | import androidx.compose.foundation.layout.padding 7 | import androidx.compose.material.IconButton 8 | import androidx.compose.material.Text 9 | import androidx.compose.runtime.Composable 10 | import androidx.compose.runtime.LaunchedEffect 11 | import androidx.compose.runtime.derivedStateOf 12 | import androidx.compose.runtime.getValue 13 | import androidx.compose.runtime.mutableStateOf 14 | import androidx.compose.runtime.remember 15 | import androidx.compose.runtime.setValue 16 | import androidx.compose.ui.Alignment 17 | import androidx.compose.ui.Modifier 18 | import androidx.compose.ui.draw.alpha 19 | import androidx.compose.ui.layout.IntrinsicMeasurable 20 | import androidx.compose.ui.layout.IntrinsicMeasureScope 21 | import androidx.compose.ui.layout.Layout 22 | import androidx.compose.ui.layout.Measurable 23 | import androidx.compose.ui.layout.MeasurePolicy 24 | import androidx.compose.ui.layout.MeasureResult 25 | import androidx.compose.ui.layout.MeasureScope 26 | import androidx.compose.ui.unit.Constraints 27 | import androidx.compose.ui.unit.dp 28 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.ChevronLeft 29 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.ChevronRight 30 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.DataTableIcons 31 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.FirstPage 32 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.LastPage 33 | 34 | @Composable 35 | internal fun PaginationBar( 36 | modifier: Modifier = Modifier, 37 | dataSize: Int, 38 | pageSizeOptions: List, 39 | defaultPageSize: Int, 40 | onPaginationChanged: (offset: Int, count: Int) -> Unit 41 | ) { 42 | 43 | var pageSize by remember { mutableStateOf(defaultPageSize) } 44 | var pageIndex by remember { mutableStateOf(0) } 45 | val pageCount by remember(pageSize, dataSize) { 46 | derivedStateOf { 47 | if (dataSize % pageSize == 0) { 48 | dataSize / pageSize 49 | } else { 50 | dataSize / pageSize + 1 51 | } 52 | } 53 | } 54 | 55 | LaunchedEffect(pageIndex, pageSize) { 56 | onPaginationChanged( 57 | pageIndex * pageSize, 58 | pageSize 59 | ) 60 | } 61 | 62 | Layout({ 63 | Row(Modifier.fillMaxHeight(), verticalAlignment = Alignment.CenterVertically) { 64 | Text("Rows per page", Modifier.padding(end = 4.dp)) 65 | DropdownPicker(pageSize, pageSizeOptions, onOptionPicked = { pageSize = it }) 66 | } 67 | 68 | Row(verticalAlignment = Alignment.CenterVertically) { 69 | val firstIndex = pageIndex * pageSize + 1 70 | val lastIndex = ((pageIndex + 1) * pageSize).coerceAtMost(dataSize) 71 | Text("$firstIndex-$lastIndex of $dataSize", Modifier.padding(horizontal = 16.dp)) 72 | IconButton( 73 | onClick = { 74 | pageIndex = 0 75 | }, 76 | Modifier.padding(end = 4.dp).alpha(if (pageIndex > 0) 1f else 0.38f), 77 | enabled = pageIndex > 0 78 | ) { Image(imageVector = DataTableIcons.FirstPage, contentDescription = "Jump to start") } 79 | IconButton( 80 | onClick = { 81 | pageIndex-- 82 | }, 83 | Modifier.padding(end = 4.dp).alpha(if (pageIndex > 0) 1f else 0.38f), 84 | enabled = pageIndex > 0 85 | ) { Image(imageVector = DataTableIcons.ChevronLeft, contentDescription = "Previous page") } 86 | IconButton( 87 | onClick = { 88 | pageIndex++ 89 | }, 90 | Modifier.padding(end = 4.dp).alpha(if (pageIndex < pageCount - 1) 1f else 0.38f), 91 | enabled = pageIndex < pageCount - 1 92 | ) { Image(imageVector = DataTableIcons.ChevronRight, contentDescription = "Next page") } 93 | IconButton( 94 | onClick = { 95 | pageIndex = pageCount - 1 96 | }, 97 | Modifier.padding(end = 4.dp).alpha(if (pageIndex < pageCount - 1) 1f else 0.38f), 98 | enabled = pageIndex < pageCount - 1 99 | ) { Image(imageVector = DataTableIcons.LastPage, contentDescription = "Jump to end") } 100 | } 101 | 102 | }, modifier, object: MeasurePolicy { 103 | override fun MeasureScope.measure( 104 | measurables: List, 105 | constraints: Constraints 106 | ): MeasureResult { 107 | 108 | val placeables = measurables.map { measurable -> 109 | measurable.measure(Constraints( 110 | maxWidth = constraints.maxWidth, 111 | )) 112 | } 113 | 114 | val (pageSizePlaceable, pageControlsPlaceable) = placeables 115 | 116 | val availableWidth = constraints.maxWidth 117 | 118 | val showPageSizeControl = 119 | availableWidth >= pageSizePlaceable.width + pageControlsPlaceable.width 120 | 121 | // Use all available width, to match the width table content 122 | // Coercing to a "big" value to circumvent the issue where the availableWidth is maxSize, 123 | // until the table content is measured. A bad workaround, indeed. 124 | return layout(availableWidth.coerceAtMost(100000), pageControlsPlaceable.height) { 125 | pageControlsPlaceable.placeRelative( 126 | availableWidth - pageControlsPlaceable.width, 127 | 0 128 | ) 129 | 130 | if (showPageSizeControl) { 131 | pageSizePlaceable.placeRelative( 132 | availableWidth - (pageControlsPlaceable.width + pageSizePlaceable.width), 133 | 0 134 | ) 135 | } 136 | } 137 | 138 | 139 | } 140 | 141 | override fun IntrinsicMeasureScope.maxIntrinsicWidth( 142 | measurables: List, 143 | height: Int 144 | ) = measurables.sumOf { 145 | it.maxIntrinsicWidth(height) 146 | } 147 | 148 | // Only the buttons are important, page size control can be omitted 149 | override fun IntrinsicMeasureScope.minIntrinsicWidth( 150 | measurables: List, 151 | height: Int 152 | ) = measurables[1].maxIntrinsicWidth(height) 153 | }) 154 | } 155 | 156 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/PlatformUtil.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | expect fun String.format(int: Int): String 4 | 5 | expect fun String.format(float: Float): String 6 | 7 | expect fun String.format(double: Double): String -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Table.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.BorderStroke 4 | import androidx.compose.foundation.background 5 | import androidx.compose.foundation.horizontalScroll 6 | import androidx.compose.foundation.interaction.MutableInteractionSource 7 | import androidx.compose.foundation.layout.Arrangement 8 | import androidx.compose.foundation.layout.fillMaxWidth 9 | import androidx.compose.foundation.layout.padding 10 | import androidx.compose.foundation.rememberScrollState 11 | import androidx.compose.foundation.text.selection.SelectionContainer 12 | import androidx.compose.foundation.verticalScroll 13 | import androidx.compose.material3.Card 14 | import androidx.compose.runtime.Composable 15 | import androidx.compose.runtime.SideEffect 16 | import androidx.compose.runtime.derivedStateOf 17 | import androidx.compose.runtime.getValue 18 | import androidx.compose.runtime.mutableStateOf 19 | import androidx.compose.runtime.remember 20 | import androidx.compose.runtime.setValue 21 | import androidx.compose.ui.Modifier 22 | import androidx.compose.ui.graphics.Color 23 | import androidx.compose.ui.layout.IntrinsicMeasurable 24 | import androidx.compose.ui.layout.IntrinsicMeasureScope 25 | import androidx.compose.ui.layout.Layout 26 | import androidx.compose.ui.layout.Measurable 27 | import androidx.compose.ui.layout.MeasureResult 28 | import androidx.compose.ui.layout.MeasureScope 29 | import androidx.compose.ui.layout.MultiContentMeasurePolicy 30 | import androidx.compose.ui.layout.Placeable 31 | import androidx.compose.ui.state.ToggleableState 32 | import androidx.compose.ui.text.style.TextAlign 33 | import androidx.compose.ui.unit.Constraints 34 | import androidx.compose.ui.unit.dp 35 | import androidx.compose.ui.unit.times 36 | import io.github.aleksandar_stefanovic.composematerialdatatable.filter.ColumnFilter 37 | import io.github.aleksandar_stefanovic.composematerialdatatable.filter.FilterBar 38 | 39 | internal enum class SortOrder { 40 | ASC, DESC 41 | } 42 | 43 | @Composable 44 | public fun Table( 45 | columnSpecs: List>, 46 | data: List, 47 | modifier: Modifier = Modifier, 48 | showSelectionColumn: Boolean = false, 49 | onSelectionChange: (Set) -> Unit = {}, 50 | showPaginationBar: Boolean = true, 51 | pageSizeOptions: List = listOf(10, 25, 50, 100), 52 | defaultPageSize: Int = 25 53 | ) { 54 | val totalFlexWeight = 55 | columnSpecs.map { it.widthSetting }.filterIsInstance().map { it.weight } 56 | .sum() 57 | 58 | var hasFlexColumns = false 59 | 60 | val columnSpecsNormalized = columnSpecs.map { 61 | if (it.widthSetting is WidthSetting.Flex) { 62 | hasFlexColumns = true 63 | val weight = it.widthSetting.weight / totalFlexWeight 64 | it.copy(widthSetting = WidthSetting.Flex(weight)) 65 | } else { 66 | it 67 | } 68 | } 69 | 70 | var sortedColumnSpec: ColumnSpec<*, *>? by remember { mutableStateOf(null) } 71 | var columnSortOrder by remember { mutableStateOf(SortOrder.ASC) } 72 | 73 | val onHeaderClick = remember<(columnSpec: ColumnSpec<*, *>) -> Unit> { 74 | { columnIndex -> 75 | if (columnIndex !== sortedColumnSpec) { 76 | sortedColumnSpec = columnIndex 77 | columnSortOrder = SortOrder.ASC 78 | } else { 79 | if (columnSortOrder == SortOrder.ASC) { 80 | columnSortOrder = SortOrder.DESC 81 | } else if (columnSortOrder == SortOrder.DESC) { 82 | // Deactivate sorting 83 | sortedColumnSpec = null 84 | } 85 | } 86 | } 87 | } 88 | 89 | var filters: List> by remember { mutableStateOf(emptyList()) } 90 | 91 | var paginationOffset: Int by remember { mutableStateOf(0) } 92 | var paginationCount: Int? by remember { 93 | mutableStateOf(if (showPaginationBar) defaultPageSize.coerceAtMost(data.size - 1) else null) 94 | } 95 | 96 | val filteredSortedData by remember(data, filters, sortedColumnSpec) { 97 | derivedStateOf { 98 | val filteredData = data.filter { item -> 99 | filters.all { it.test(item) } 100 | } 101 | 102 | if (sortedColumnSpec != null) { 103 | if (columnSortOrder == SortOrder.DESC) { 104 | filteredData.sortedBy { 105 | @Suppress("UNCHECKED_CAST") 106 | (sortedColumnSpec!!.valueSelector as (T) -> Comparable).invoke(it) 107 | } 108 | } else { 109 | filteredData.sortedByDescending { 110 | @Suppress("UNCHECKED_CAST") 111 | (sortedColumnSpec!!.valueSelector as (T) -> Comparable).invoke(it) 112 | } 113 | } 114 | } else filteredData 115 | } 116 | } 117 | 118 | val paginatedData by remember(filteredSortedData, paginationOffset, paginationCount) { 119 | derivedStateOf { 120 | return@derivedStateOf if (paginationCount != null) { 121 | val lastIndex = (paginationOffset + paginationCount!!).coerceAtMost(filteredSortedData.size) 122 | filteredSortedData.slice(paginationOffset..>(setOf()) } 128 | 129 | SideEffect { 130 | onSelectionChange(selectedData) 131 | } 132 | 133 | val headerSelectionCheckboxState by remember(selectedData) { 134 | derivedStateOf { 135 | when (selectedData.size) { 136 | 0 -> ToggleableState.Off 137 | data.size -> ToggleableState.On 138 | else -> ToggleableState.Indeterminate 139 | } 140 | } 141 | } 142 | 143 | val onHeaderSelectionClick = remember { 144 | { 145 | selectedData = if (headerSelectionCheckboxState == ToggleableState.On) { 146 | emptySet() 147 | } else { 148 | paginatedData.toSet() 149 | } 150 | } 151 | } 152 | 153 | val onBodySelectionClick: (dataItem: T) -> Unit = remember { 154 | { index -> 155 | if (index !in selectedData) { 156 | selectedData += index 157 | } else { 158 | selectedData -= index 159 | } 160 | } 161 | } 162 | 163 | val headerRowComposableLambda: @Composable () -> Unit = { 164 | if (showSelectionColumn) { 165 | CheckboxHeader(headerSelectionCheckboxState, onHeaderSelectionClick) 166 | } 167 | columnSpecsNormalized.map { columnSpec -> 168 | val sortOrder = if (columnSpec == sortedColumnSpec) columnSortOrder else null 169 | 170 | TextHeader( 171 | columnSpec.headerName, 172 | columnSpec.horizontalArrangement, 173 | sortOrder, 174 | onClick = { onHeaderClick(columnSpec) } 175 | ) 176 | } 177 | } 178 | 179 | val composableLambdasByRow: List<@Composable () -> Unit> = paginatedData.map { rowData -> 180 | 181 | // Used to share hover interaction across multiple composables in a row 182 | val interactionSource = remember { MutableInteractionSource() } 183 | 184 | // One lambda per row (will become List> in the Layout composable) 185 | return@map { 186 | if (showSelectionColumn) { 187 | CheckboxCell(rowData in selectedData, interactionSource) { onBodySelectionClick(rowData) } 188 | } 189 | columnSpecsNormalized.forEach { columnSpec -> 190 | 191 | val textAlign = when (columnSpec.horizontalArrangement) { 192 | Arrangement.Start -> TextAlign.Start 193 | Arrangement.End -> TextAlign.End 194 | else -> TextAlign.Center 195 | } 196 | 197 | when (columnSpec) { 198 | is TextColumnSpec -> TextCell(columnSpec.valueSelector(rowData), textAlign, interactionSource) 199 | is IntColumnSpec -> IntCell(columnSpec.valueSelector(rowData), columnSpec.numberFormat, textAlign, interactionSource) 200 | is DoubleColumnSpec -> DoubleCell(columnSpec.valueSelector(rowData), columnSpec.numberFormat, textAlign, interactionSource) 201 | is DateColumnSpec -> DateCell(columnSpec.valueSelector(rowData), columnSpec.dateFormat, textAlign, interactionSource) 202 | is CheckboxColumnSpec -> CheckboxCell(columnSpec.valueSelector(rowData), interactionSource, onClick = { }) // TODO 203 | is DropdownColumnSpec -> DropdownCell(columnSpec, rowData, interactionSource) 204 | } 205 | } 206 | } 207 | } 208 | 209 | // Header is appended to body rows in order to calculate the column width together 210 | // TODO headers should not figure into the column width, text should be truncated instead 211 | val headerAndBodyRowComposables: List<@Composable () -> Unit> = listOf(headerRowComposableLambda) + composableLambdasByRow 212 | 213 | SelectionContainer { 214 | Card(modifier, border = BorderStroke(1.dp, Color(0x1f000000))) { 215 | 216 | FilterBar( 217 | Modifier.fillMaxWidth().background(Color.White), 218 | columnSpecsNormalized, 219 | filters, 220 | onFilterConfirm = { filters += it }, 221 | onRemoveFilter = { filters -= it } 222 | ) 223 | 224 | val horizontalScrollState = rememberScrollState() 225 | val verticalScrollState = rememberScrollState() 226 | 227 | // If there are any flex columns, horizontal scroll is not set, since the width is unconstrained 228 | val layoutModifier = if (hasFlexColumns) Modifier else Modifier.horizontalScroll(horizontalScrollState) 229 | 230 | Layout( 231 | headerAndBodyRowComposables, 232 | modifier = layoutModifier.weight(1f, false).verticalScroll(verticalScrollState).background(Color(0x0f000000)), 233 | measurePolicy = object : MultiContentMeasurePolicy { 234 | 235 | val totalColumnCount = 236 | columnSpecsNormalized.size + if (showSelectionColumn) 1 else 0 237 | 238 | // By spec, it should be 1.dp, but it doesn't work as intended when converted to px, TODO find an elegant solution 239 | val borderPx = 1 240 | val totalVerticalPadding = headerAndBodyRowComposables.size * borderPx 241 | 242 | override fun MeasureScope.measure( 243 | // Each element in the outer list is a single row 244 | measurables: List>, 245 | constraints: Constraints 246 | ): MeasureResult { 247 | 248 | val availableWidth = constraints.maxWidth 249 | 250 | val columnWidthsInitial: List = (0.. 251 | // Account for the selection column 252 | val widthSetting = if (showSelectionColumn) { 253 | if (colIndex == 0) { 254 | WidthSetting.WrapContent 255 | } else { 256 | columnSpecs[colIndex - 1].widthSetting 257 | } 258 | } else { 259 | columnSpecs[colIndex].widthSetting 260 | } 261 | 262 | return@map when (widthSetting) { 263 | is WidthSetting.Flex -> 0 // Will be set at a later point 264 | is WidthSetting.Static -> widthSetting.width.roundToPx() 265 | WidthSetting.WrapContent -> { 266 | // Iterate over all the measurables in this row, find the widest one 267 | measurables.maxOf { rowMeasurables -> 268 | val targetHeight = 56.dp // Per Material specs 269 | rowMeasurables[colIndex].maxIntrinsicWidth(targetHeight.roundToPx()) 270 | } 271 | } 272 | } 273 | } 274 | 275 | val remainingWidth = (availableWidth - columnWidthsInitial.sum()).coerceAtLeast(0) 276 | 277 | // Calculate width of the flex columns based on the remaining width 278 | val columnWidths = (columnWidthsInitial).mapIndexed { colIndex, width -> 279 | val widthSetting = if (showSelectionColumn) { 280 | if (colIndex == 0) { 281 | WidthSetting.WrapContent 282 | } else { 283 | columnSpecsNormalized[colIndex - 1].widthSetting 284 | } 285 | } else { 286 | columnSpecsNormalized[colIndex].widthSetting 287 | } 288 | if (widthSetting is WidthSetting.Flex) { 289 | (remainingWidth * widthSetting.weight).toInt() 290 | } else { 291 | width 292 | } 293 | } 294 | 295 | val placeablesByRow: List> = 296 | measurables.map { rowMeasurables -> 297 | val targetHeight = 56.dp.roundToPx() 298 | rowMeasurables.mapIndexed { colIndex, measurable -> 299 | val columnWidth = columnWidths[colIndex] 300 | val cellConstraints = Constraints( 301 | minWidth = columnWidth, 302 | maxWidth = columnWidth, 303 | minHeight = targetHeight, 304 | maxHeight = targetHeight 305 | ) 306 | measurable.measure(cellConstraints) 307 | } 308 | } 309 | 310 | 311 | val tallestCellHeightByRow = placeablesByRow.map { rowPlaceables -> 312 | rowPlaceables.maxOf { it.height } 313 | } 314 | 315 | val widestCellByColumn = (0.. 316 | placeablesByRow.maxOf { rowPlaceables -> 317 | rowPlaceables[colIndex].width 318 | } 319 | } 320 | 321 | val tableHeight = 322 | (tallestCellHeightByRow.sum() + totalVerticalPadding).coerceAtMost(constraints.maxHeight) 323 | val tableWidth = 324 | (widestCellByColumn.sum()).coerceAtMost(constraints.maxWidth) 325 | 326 | return layout(tableWidth, tableHeight) { 327 | var yPosition = borderPx 328 | 329 | placeablesByRow.forEachIndexed { rowIndex, rowPlaceables -> 330 | var xPosition = 0 331 | rowPlaceables.forEach { placeable -> 332 | placeable.placeRelative(xPosition, yPosition) 333 | xPosition += placeable.width 334 | } 335 | yPosition += tallestCellHeightByRow[rowIndex] + borderPx 336 | } 337 | } 338 | } 339 | 340 | // There isn't really any functionality in the spec to define how the table 341 | // should respond to the available width, so the min and max intrinsic heights 342 | // are the same 343 | override fun IntrinsicMeasureScope.maxIntrinsicHeight( 344 | measurables: List>, 345 | width: Int 346 | ) = minIntrinsicHeight(measurables, width) 347 | 348 | override fun IntrinsicMeasureScope.minIntrinsicHeight( 349 | measurables: List>, 350 | width: Int 351 | ): Int { 352 | val headerHeight = 56.dp 353 | // Deducting one from size because that's the header row 354 | val totalRowHeight = (measurables.size - 1) * 52.dp 355 | return (headerHeight + totalRowHeight).roundToPx() + totalVerticalPadding 356 | } 357 | 358 | override fun IntrinsicMeasureScope.maxIntrinsicWidth( 359 | measurables: List>, 360 | height: Int 361 | ): Int { 362 | // If there are any flex columns, table width is unbound 363 | return if (columnSpecsNormalized.any { it.widthSetting is WidthSetting.Flex }) { 364 | Constraints.Infinity 365 | } else { 366 | // Spec doesn't define responsiveness of the table based on the given 367 | // height, so min and max intrinsic widths are the same 368 | this.minIntrinsicWidth(measurables, height) 369 | } 370 | } 371 | 372 | // When calculating the min width, flex columns are reduced to 0 373 | override fun IntrinsicMeasureScope.minIntrinsicWidth( 374 | measurables: List>, 375 | height: Int 376 | ): Int { 377 | val widths = columnSpecsNormalized.mapIndexed { colIndex, columnSpec -> 378 | when (columnSpec.widthSetting) { 379 | is WidthSetting.Flex -> 0 380 | is WidthSetting.Static -> columnSpec.widthSetting.width.roundToPx() 381 | is WidthSetting.WrapContent -> { 382 | measurables.mapIndexed { index, measurables -> 383 | val rowHeight = 384 | (if (index == 0) 56.dp else 52.dp).roundToPx() 385 | val cIndex = 386 | if (showSelectionColumn) colIndex + 1 else colIndex 387 | val measurable = measurables[cIndex] 388 | measurable.maxIntrinsicWidth(rowHeight) 389 | }.max() // Return the biggest intrinsic width 390 | } 391 | } 392 | } 393 | 394 | val selectionColumnWidth = if (showSelectionColumn) { 395 | val selectionHeaderCellMeasurable = measurables[0][0] 396 | selectionHeaderCellMeasurable.maxIntrinsicWidth(56.dp.roundToPx()) 397 | } else 0 398 | return widths.sum() + selectionColumnWidth 399 | } 400 | } 401 | ) 402 | 403 | if (showPaginationBar) { 404 | PaginationBar( 405 | Modifier.fillMaxWidth().padding(top = 1.dp).background(Color.White), 406 | filteredSortedData.size, 407 | pageSizeOptions, 408 | defaultPageSize, 409 | onPaginationChanged = { offset, count -> 410 | paginationOffset = offset 411 | paginationCount = count 412 | } 413 | ) 414 | } 415 | } 416 | } 417 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Util.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.ui.Modifier 4 | import androidx.compose.ui.input.key.Key 5 | import androidx.compose.ui.input.key.key 6 | import androidx.compose.ui.input.key.onKeyEvent 7 | 8 | internal inline fun Modifier.onEnterPress(crossinline action: () -> Unit): Modifier { 9 | return this.onKeyEvent { event -> 10 | if (event.key == Key.Enter) { 11 | action() 12 | return@onKeyEvent true 13 | } else { 14 | return@onKeyEvent false 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/CheckboxFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.Row 6 | import androidx.compose.foundation.layout.fillMaxWidth 7 | import androidx.compose.foundation.layout.padding 8 | import androidx.compose.material.Text 9 | import androidx.compose.material.TextButton 10 | import androidx.compose.material3.FilledTonalButton 11 | import androidx.compose.runtime.Composable 12 | import androidx.compose.runtime.getValue 13 | import androidx.compose.runtime.mutableStateOf 14 | import androidx.compose.runtime.remember 15 | import androidx.compose.runtime.setValue 16 | import androidx.compose.ui.Modifier 17 | import androidx.compose.ui.unit.dp 18 | import io.github.aleksandar_stefanovic.composematerialdatatable.CheckboxColumnSpec 19 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 20 | 21 | @Composable 22 | internal fun CheckboxFilterModal( 23 | columnSpec: CheckboxColumnSpec, 24 | onFilterConfirm: (BooleanFilter) -> Unit, 25 | onClose: () -> Unit 26 | ) { 27 | Column { 28 | val predicates = listOf( 29 | FilterPredicate.SELECTED, 30 | FilterPredicate.NOT_SELECTED 31 | ) 32 | 33 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 34 | 35 | DropdownPicker( 36 | selectedPredicate, 37 | predicates, 38 | valueFormatter = { it.verb }, 39 | onOptionPicked = { selectedPredicate = it } 40 | ) 41 | 42 | Row( 43 | Modifier.fillMaxWidth().padding(top = 12.dp), 44 | horizontalArrangement = Arrangement.End 45 | ) { 46 | TextButton( 47 | onClose, 48 | Modifier.padding(end = 8.dp) 49 | ) { Text("Cancel") } 50 | FilledTonalButton(onClick = { 51 | val filter = BooleanFilter(columnSpec, selectedPredicate) 52 | onFilterConfirm(filter) 53 | }) { Text("Apply") } 54 | } 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/ColumnFilter.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import io.github.aleksandar_stefanovic.composematerialdatatable.CheckboxColumnSpec 4 | import io.github.aleksandar_stefanovic.composematerialdatatable.ColumnSpec 5 | import io.github.aleksandar_stefanovic.composematerialdatatable.DateColumnSpec 6 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownColumnSpec 7 | import io.github.aleksandar_stefanovic.composematerialdatatable.TextColumnSpec 8 | import kotlinx.datetime.LocalDate 9 | 10 | // A single predicate enum for all types of filters, a single enum can be applicable to multiple 11 | // types, for example, "IS" works on all scalar types 12 | internal enum class FilterPredicate(val verb: String) { 13 | CONTAINS("contains"), 14 | NOT_CONTAINS("doesn't contain"), 15 | IS("is"), 16 | NOT_IS("is not"), 17 | STARTS_WITH("starts with"), 18 | ENDS_WITH("ends with"), 19 | 20 | GREATER_THAN("greater than"), 21 | GREATER_THAN_EQUALS("greater or equal than"), 22 | LESS_THAN("less than"), 23 | LESS_THAN_EQUALS("less or equal than"), 24 | BETWEEN("between"), 25 | 26 | SELECTED("selected"), 27 | NOT_SELECTED("not selected"), 28 | 29 | IS_ANY_OF("is any of"), 30 | IS_NONE_OF("is none of") 31 | } 32 | 33 | internal abstract class ColumnFilter>(val columnSpec: ColumnSpec) { 34 | abstract fun test(item: T): Boolean 35 | abstract val label: String 36 | } 37 | 38 | internal class StringFilter( 39 | columnSpec: TextColumnSpec, private val predicate: FilterPredicate, private val term: String 40 | ) : ColumnFilter(columnSpec) { 41 | 42 | override val label = "${columnSpec.headerName} ${predicate.verb} $term" 43 | 44 | override fun test(item: T): Boolean { 45 | val value = columnSpec.valueSelector(item) 46 | 47 | return when (predicate) { 48 | FilterPredicate.CONTAINS -> value.contains(term, ignoreCase = true) 49 | FilterPredicate.NOT_CONTAINS -> !value.contains(term, ignoreCase = true) 50 | FilterPredicate.IS -> value.equals(term, ignoreCase = true) 51 | FilterPredicate.NOT_IS -> !value.equals(term, ignoreCase = true) 52 | FilterPredicate.STARTS_WITH -> value.startsWith(term, ignoreCase = true) 53 | FilterPredicate.ENDS_WITH -> value.endsWith(term, ignoreCase = true) 54 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 55 | } 56 | } 57 | } 58 | 59 | internal class NumberFilter( 60 | columnSpec: ColumnSpec, 61 | private val predicate: FilterPredicate, 62 | private val parameters: List 63 | ) : 64 | ColumnFilter(columnSpec) where S : Number, S : Comparable { 65 | 66 | override fun test(item: T): Boolean { 67 | val value = columnSpec.valueSelector(item) 68 | 69 | return when (predicate) { 70 | FilterPredicate.IS -> parameters[0] == value 71 | FilterPredicate.NOT_IS -> parameters[0] != value 72 | FilterPredicate.GREATER_THAN -> value > parameters[0] 73 | FilterPredicate.GREATER_THAN_EQUALS -> value >= parameters[0] 74 | FilterPredicate.LESS_THAN -> value < parameters[0] 75 | FilterPredicate.LESS_THAN_EQUALS -> value <= parameters[0] 76 | FilterPredicate.BETWEEN -> value in parameters[0]..parameters[1] 77 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 78 | } 79 | } 80 | 81 | override val label: String 82 | get() = when (predicate) { 83 | FilterPredicate.IS, 84 | FilterPredicate.NOT_IS, 85 | FilterPredicate.GREATER_THAN, 86 | FilterPredicate.GREATER_THAN_EQUALS, 87 | FilterPredicate.LESS_THAN, 88 | FilterPredicate.LESS_THAN_EQUALS -> "${columnSpec.headerName} ${predicate.verb} ${parameters.first()}" 89 | FilterPredicate.BETWEEN -> "${columnSpec.headerName} is between ${parameters[0]} and ${parameters[1]}" 90 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 91 | } 92 | 93 | } 94 | 95 | internal class BooleanFilter( 96 | columnSpec: CheckboxColumnSpec, 97 | private val predicate: FilterPredicate 98 | ) : ColumnFilter(columnSpec) { 99 | override fun test(item: T): Boolean { 100 | val selected = columnSpec.valueSelector(item) 101 | return when (predicate) { 102 | FilterPredicate.SELECTED -> selected 103 | FilterPredicate.NOT_SELECTED -> !selected 104 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 105 | } 106 | } 107 | 108 | override val label: String = when (predicate) { 109 | FilterPredicate.SELECTED, 110 | FilterPredicate.NOT_SELECTED -> "${columnSpec.headerName} is ${predicate.verb}" 111 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 112 | } 113 | } 114 | 115 | internal class DateFilter( 116 | columnSpec: DateColumnSpec, 117 | private val predicate: FilterPredicate, 118 | private val value: LocalDate 119 | ) : ColumnFilter(columnSpec) { 120 | override fun test(item: T): Boolean { 121 | val selected = columnSpec.valueSelector(item) 122 | return when (predicate) { 123 | FilterPredicate.IS -> selected == value 124 | FilterPredicate.GREATER_THAN -> selected > value 125 | FilterPredicate.LESS_THAN -> selected < value 126 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 127 | } 128 | } 129 | 130 | override val label: String by lazy { 131 | val formattedValue = columnSpec.dateFormat.format(value) 132 | when (predicate) { 133 | FilterPredicate.IS -> "${columnSpec.headerName} is $formattedValue" 134 | FilterPredicate.GREATER_THAN -> "${columnSpec.headerName} is after $formattedValue" 135 | FilterPredicate.LESS_THAN -> "${columnSpec.headerName} is before $formattedValue" 136 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 137 | } 138 | } 139 | } 140 | 141 | internal class DropdownFilter>( 142 | columnSpec: DropdownColumnSpec, 143 | private val predicate: FilterPredicate, 144 | private val values: List 145 | ) : ColumnFilter(columnSpec) { 146 | 147 | override fun test(item: T): Boolean { 148 | val value = columnSpec.valueSelector(item) 149 | return when (predicate) { 150 | FilterPredicate.IS_ANY_OF -> value in values 151 | FilterPredicate.IS_NONE_OF -> value !in values 152 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 153 | } 154 | } 155 | 156 | override val label: String by lazy { 157 | val valueList = values.map { columnSpec.valueFormatter(it) }.joinToString(", ") 158 | when (predicate) { 159 | FilterPredicate.IS_ANY_OF -> "${columnSpec.headerName} is any of $valueList" 160 | FilterPredicate.IS_NONE_OF -> "${columnSpec.headerName} is none of $valueList" 161 | else -> throw Error("Filter predicate ${predicate.verb} is not supported") 162 | } 163 | } 164 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/DateFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.background 5 | import androidx.compose.foundation.layout.Arrangement 6 | import androidx.compose.foundation.layout.Box 7 | import androidx.compose.foundation.layout.Column 8 | import androidx.compose.foundation.layout.Row 9 | import androidx.compose.foundation.layout.fillMaxWidth 10 | import androidx.compose.foundation.layout.padding 11 | import androidx.compose.foundation.layout.width 12 | import androidx.compose.material.Button 13 | import androidx.compose.material.IconButton 14 | import androidx.compose.material.OutlinedTextField 15 | import androidx.compose.material.Text 16 | import androidx.compose.material.TextButton 17 | import androidx.compose.material3.DatePicker 18 | import androidx.compose.material3.ExperimentalMaterial3Api 19 | import androidx.compose.material3.FilledTonalButton 20 | import androidx.compose.material3.MaterialTheme 21 | import androidx.compose.material3.rememberDatePickerState 22 | import androidx.compose.runtime.Composable 23 | import androidx.compose.runtime.getValue 24 | import androidx.compose.runtime.mutableStateOf 25 | import androidx.compose.runtime.remember 26 | import androidx.compose.runtime.setValue 27 | import androidx.compose.ui.Alignment 28 | import androidx.compose.ui.Modifier 29 | import androidx.compose.ui.draw.shadow 30 | import androidx.compose.ui.unit.dp 31 | import androidx.compose.ui.window.Popup 32 | import io.github.aleksandar_stefanovic.composematerialdatatable.DateColumnSpec 33 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 34 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.DataTableIcons 35 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.DateRange 36 | import kotlinx.datetime.Instant 37 | import kotlinx.datetime.LocalDate 38 | import kotlinx.datetime.TimeZone 39 | import kotlinx.datetime.toLocalDateTime 40 | 41 | @OptIn(ExperimentalMaterial3Api::class) 42 | @Composable 43 | internal fun DateFilterModal( 44 | columnSpec: DateColumnSpec, 45 | onFilterConfirm: (DateFilter) -> Unit, 46 | onClose: () -> Unit 47 | ) { 48 | val predicates = listOf( 49 | FilterPredicate.IS, 50 | FilterPredicate.LESS_THAN, 51 | FilterPredicate.GREATER_THAN 52 | ) 53 | 54 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 55 | 56 | Column { 57 | DropdownPicker( 58 | selectedPredicate, 59 | predicates, 60 | valueFormatter = { when (it) { 61 | FilterPredicate.IS -> "is" 62 | FilterPredicate.LESS_THAN -> "is before" 63 | FilterPredicate.GREATER_THAN -> "is after" 64 | else -> throw Error("Predicate $it not supported") 65 | } }, 66 | onOptionPicked = { selectedPredicate = it } 67 | ) 68 | 69 | var showDatePicker by remember { mutableStateOf(false) } 70 | val datePickerState = rememberDatePickerState() 71 | var selectedDate: LocalDate? by remember { mutableStateOf(null) } 72 | 73 | fun applyDateFromState() { 74 | selectedDate = datePickerState.selectedDateMillis?.let { 75 | Instant.fromEpochMilliseconds(it) 76 | .toLocalDateTime(TimeZone.currentSystemDefault()) 77 | .date 78 | } 79 | } 80 | 81 | val selectedDateText = selectedDate?.let { 82 | columnSpec.dateFormat.format(it) 83 | } ?: "" 84 | 85 | Box( 86 | modifier = Modifier.fillMaxWidth() 87 | ) { 88 | OutlinedTextField( 89 | value = selectedDateText, 90 | onValueChange = { }, 91 | readOnly = true, 92 | trailingIcon = { 93 | IconButton(onClick = { showDatePicker = !showDatePicker }) { 94 | Image( 95 | imageVector = DataTableIcons.DateRange, 96 | contentDescription = "Date picker" 97 | ) 98 | } 99 | }, 100 | modifier = Modifier 101 | .fillMaxWidth() 102 | ) 103 | 104 | if (showDatePicker) { 105 | Popup( 106 | onDismissRequest = { showDatePicker = false }, 107 | alignment = Alignment.TopStart 108 | ) { 109 | Column( 110 | modifier = Modifier 111 | .shadow(elevation = 4.dp) 112 | .background(MaterialTheme.colorScheme.surface) 113 | .width(450.dp) 114 | .padding(16.dp) 115 | ) { 116 | DatePicker( 117 | state = datePickerState, 118 | showModeToggle = false, 119 | title = null, 120 | headline = null 121 | 122 | ) 123 | Button({ applyDateFromState(); showDatePicker = false}, Modifier.align(Alignment.End)) { 124 | Text("Confirm") 125 | } 126 | } 127 | } 128 | } 129 | } 130 | 131 | Row( 132 | Modifier.fillMaxWidth().padding(top = 12.dp), 133 | horizontalArrangement = Arrangement.End 134 | ) { 135 | TextButton( 136 | onClose, 137 | Modifier.padding(end = 8.dp) 138 | ) { Text("Cancel") } 139 | FilledTonalButton(onClick = { 140 | if (selectedDate != null) { 141 | onFilterConfirm(DateFilter(columnSpec, selectedPredicate, selectedDate!!)) 142 | } 143 | }) { Text("Apply") } 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/DoubleFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.Row 6 | import androidx.compose.foundation.layout.fillMaxWidth 7 | import androidx.compose.foundation.layout.padding 8 | import androidx.compose.foundation.text.KeyboardOptions 9 | import androidx.compose.material.OutlinedTextField 10 | import androidx.compose.material.Text 11 | import androidx.compose.material.TextButton 12 | import androidx.compose.material3.FilledTonalButton 13 | import androidx.compose.runtime.Composable 14 | import androidx.compose.runtime.derivedStateOf 15 | import androidx.compose.runtime.getValue 16 | import androidx.compose.runtime.mutableStateOf 17 | import androidx.compose.runtime.remember 18 | import androidx.compose.runtime.setValue 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.text.input.KeyboardType 21 | import androidx.compose.ui.unit.dp 22 | import io.github.aleksandar_stefanovic.composematerialdatatable.DoubleColumnSpec 23 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 24 | import io.github.aleksandar_stefanovic.composematerialdatatable.onEnterPress 25 | 26 | @Composable 27 | internal fun DoubleFilterModal( 28 | columnSpec: DoubleColumnSpec, 29 | onFilterConfirm: (NumberFilter) -> Unit, 30 | onClose: () -> Unit 31 | ) { 32 | val predicates = listOf( 33 | FilterPredicate.IS, 34 | FilterPredicate.NOT_IS, 35 | FilterPredicate.GREATER_THAN, 36 | FilterPredicate.GREATER_THAN_EQUALS, 37 | FilterPredicate.LESS_THAN, 38 | FilterPredicate.LESS_THAN_EQUALS, 39 | FilterPredicate.BETWEEN 40 | ) 41 | 42 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 43 | 44 | var firstText by remember { mutableStateOf("") } 45 | val firstValue: Double? by remember(firstText) { 46 | derivedStateOf { 47 | firstText.toDoubleOrNull() 48 | } 49 | } 50 | 51 | var secondText by remember { mutableStateOf("") } 52 | val secondValue: Double? by remember(secondText) { 53 | derivedStateOf { 54 | secondText.toDoubleOrNull() 55 | } 56 | } 57 | 58 | val canConfirm by remember(selectedPredicate, firstValue, secondValue) { 59 | derivedStateOf { 60 | if (selectedPredicate == FilterPredicate.BETWEEN) { 61 | firstValue != null && secondValue != null 62 | } else { 63 | firstValue != null 64 | } 65 | } 66 | } 67 | 68 | val onConfirm = { 69 | if (canConfirm) { 70 | onFilterConfirm(NumberFilter(columnSpec, selectedPredicate, listOf(firstValue!!, secondValue ?: 0.0))) 71 | } 72 | } 73 | 74 | Column { 75 | DropdownPicker( 76 | selectedPredicate, 77 | predicates, 78 | valueFormatter = { it.verb }, 79 | onOptionPicked = { selectedPredicate = it } 80 | ) 81 | 82 | Row { 83 | OutlinedTextField( 84 | firstText, 85 | onValueChange = { firstText = it; }, 86 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), 87 | isError = firstValue == null && firstText != "", 88 | modifier = Modifier.onEnterPress(onConfirm), 89 | singleLine = true 90 | ) 91 | 92 | if (selectedPredicate == FilterPredicate.BETWEEN) { 93 | Text(" and ") 94 | OutlinedTextField( 95 | secondText, 96 | onValueChange = { secondText = it; }, 97 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), 98 | isError = secondValue == null && secondText != "", 99 | modifier = Modifier.onEnterPress(onConfirm), 100 | singleLine = true 101 | ) 102 | } 103 | } 104 | 105 | Row( 106 | Modifier.fillMaxWidth().padding(top = 12.dp), 107 | horizontalArrangement = Arrangement.End 108 | ) { 109 | TextButton( 110 | onClose, 111 | Modifier.padding(end = 8.dp) 112 | ) { Text("Cancel") } 113 | FilledTonalButton(onClick = onConfirm, enabled = canConfirm) { Text("Apply") } 114 | } 115 | 116 | } 117 | 118 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/DropdownFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.clickable 4 | import androidx.compose.foundation.layout.Arrangement 5 | import androidx.compose.foundation.layout.Column 6 | import androidx.compose.foundation.layout.Row 7 | import androidx.compose.foundation.layout.fillMaxWidth 8 | import androidx.compose.foundation.layout.height 9 | import androidx.compose.foundation.layout.padding 10 | import androidx.compose.foundation.layout.width 11 | import androidx.compose.foundation.lazy.LazyColumn 12 | import androidx.compose.material.Checkbox 13 | import androidx.compose.material.Text 14 | import androidx.compose.material.TextButton 15 | import androidx.compose.material3.FilledTonalButton 16 | import androidx.compose.runtime.Composable 17 | import androidx.compose.runtime.getValue 18 | import androidx.compose.runtime.mutableStateOf 19 | import androidx.compose.runtime.remember 20 | import androidx.compose.runtime.setValue 21 | import androidx.compose.ui.Alignment 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.unit.dp 24 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownColumnSpec 25 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 26 | 27 | @Composable 28 | internal fun > DropdownFilterModal( 29 | columnSpec: DropdownColumnSpec, 30 | onFilterConfirm: (DropdownFilter) -> Unit, 31 | onClose: () -> Unit 32 | ) { 33 | 34 | val predicates = listOf( 35 | FilterPredicate.IS_ANY_OF, 36 | FilterPredicate.IS_NONE_OF 37 | ) 38 | 39 | var options: List> by remember { 40 | mutableStateOf(columnSpec.choices.map { it to false }) 41 | } 42 | 43 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 44 | 45 | Column { 46 | DropdownPicker( 47 | selectedPredicate, 48 | predicates, 49 | valueFormatter = { it.verb }, 50 | onOptionPicked = { selectedPredicate = it } 51 | ) 52 | 53 | LazyColumn(Modifier.width(200.dp).height((52 * options.size.coerceAtMost(8)).dp)) { 54 | items(options.size) { index -> 55 | val option = options[index] 56 | 57 | Row(Modifier.clickable { 58 | options = options.map { 59 | if (it == option) { 60 | Pair(it.first, !it.second) 61 | } else { 62 | it 63 | } 64 | } 65 | }) { 66 | Checkbox(option.second, onCheckedChange = { 67 | options = options.map { 68 | if (it == option) { 69 | Pair(it.first, !it.second) 70 | } else { 71 | it 72 | } 73 | } 74 | }) 75 | Text(columnSpec.valueFormatter(option.first), Modifier.align(Alignment.CenterVertically)) 76 | } 77 | } 78 | } 79 | 80 | Row( 81 | Modifier.fillMaxWidth().padding(top = 12.dp), 82 | horizontalArrangement = Arrangement.End 83 | ) { 84 | TextButton( 85 | onClose, 86 | Modifier.padding(end = 8.dp) 87 | ) { Text("Cancel") } 88 | FilledTonalButton(enabled = predicates.isNotEmpty(), onClick = { 89 | val selectedOptions = options.filter { it.second }.map { it.first } 90 | onFilterConfirm(DropdownFilter(columnSpec, selectedPredicate, selectedOptions)) 91 | }, ) { 92 | Text("Apply") 93 | } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/FilterBar.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.Image 4 | import androidx.compose.foundation.layout.Row 5 | import androidx.compose.foundation.layout.padding 6 | import androidx.compose.foundation.layout.size 7 | import androidx.compose.material.DropdownMenu 8 | import androidx.compose.material.DropdownMenuItem 9 | import androidx.compose.material.IconButton 10 | import androidx.compose.material.MaterialTheme 11 | import androidx.compose.material.Text 12 | import androidx.compose.material3.InputChip 13 | import androidx.compose.material3.InputChipDefaults 14 | import androidx.compose.runtime.Composable 15 | import androidx.compose.runtime.getValue 16 | import androidx.compose.runtime.mutableStateOf 17 | import androidx.compose.runtime.remember 18 | import androidx.compose.runtime.setValue 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.graphics.Color 21 | import androidx.compose.ui.unit.dp 22 | import io.github.aleksandar_stefanovic.composematerialdatatable.CheckboxColumnSpec 23 | import io.github.aleksandar_stefanovic.composematerialdatatable.ColumnSpec 24 | import io.github.aleksandar_stefanovic.composematerialdatatable.DateColumnSpec 25 | import io.github.aleksandar_stefanovic.composematerialdatatable.DoubleColumnSpec 26 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownColumnSpec 27 | import io.github.aleksandar_stefanovic.composematerialdatatable.IntColumnSpec 28 | import io.github.aleksandar_stefanovic.composematerialdatatable.TextColumnSpec 29 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.Close 30 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.DataTableIcons 31 | import io.github.aleksandar_stefanovic.composematerialdatatable.icons.FilterList 32 | 33 | @Composable 34 | internal fun FilterBar( 35 | modifier: Modifier = Modifier, 36 | columnSpecs: List>, 37 | filters: List>, 38 | onFilterConfirm: (columnFilter: ColumnFilter) -> Unit, 39 | onRemoveFilter: (ColumnFilter) -> Unit 40 | ) { 41 | 42 | var showFilterPicker by remember { mutableStateOf(false) } 43 | var showFilterSetup by remember { mutableStateOf(false) } 44 | var selectedColumnSpec: ColumnSpec? by remember { mutableStateOf(null) } 45 | 46 | Row(modifier) { 47 | IconButton(onClick = { showFilterPicker = !showFilterPicker }) { 48 | Image(imageVector = DataTableIcons.FilterList, contentDescription = "Filter") 49 | } 50 | DropdownMenu(showFilterPicker, onDismissRequest = { showFilterPicker = false }) { 51 | columnSpecs.forEach { columnSpec -> 52 | DropdownMenuItem({ 53 | selectedColumnSpec = columnSpec; showFilterPicker = false; showFilterSetup = 54 | true 55 | }) { 56 | Text(columnSpec.headerName) 57 | } 58 | } 59 | } 60 | // Dropdown menu used as a Popup because it's simpler to use and has animations 61 | DropdownMenu( 62 | showFilterSetup, 63 | modifier = Modifier.padding(16.dp), 64 | onDismissRequest = { showFilterSetup = false }) { 65 | Text(selectedColumnSpec?.headerName ?: "", style = MaterialTheme.typography.h6) 66 | 67 | when (selectedColumnSpec!!) { 68 | is TextColumnSpec -> TextFilterModal( 69 | selectedColumnSpec as TextColumnSpec, 70 | onFilterConfirm = { columnFilter -> 71 | showFilterSetup = false 72 | showFilterPicker = false 73 | onFilterConfirm(columnFilter) 74 | }, 75 | onClose = { showFilterSetup = false } 76 | ) 77 | 78 | is IntColumnSpec -> IntFilterModal( 79 | selectedColumnSpec as IntColumnSpec, 80 | onFilterConfirm = { columnFilter -> 81 | showFilterSetup = false 82 | showFilterPicker = false 83 | onFilterConfirm(columnFilter) 84 | }, 85 | onClose = { showFilterSetup = false } 86 | ) 87 | 88 | is DoubleColumnSpec -> DoubleFilterModal( 89 | selectedColumnSpec as DoubleColumnSpec, 90 | onFilterConfirm = { columnFilter -> 91 | showFilterSetup = false 92 | showFilterPicker = false 93 | onFilterConfirm(columnFilter) 94 | }, 95 | onClose = { showFilterSetup = false } 96 | ) 97 | 98 | is CheckboxColumnSpec -> CheckboxFilterModal( 99 | selectedColumnSpec as CheckboxColumnSpec, 100 | onFilterConfirm = { columnFilter -> 101 | showFilterSetup = false 102 | showFilterPicker = false 103 | onFilterConfirm(columnFilter) 104 | }, 105 | onClose = { showFilterSetup = false } 106 | ) 107 | 108 | is DateColumnSpec -> DateFilterModal( 109 | selectedColumnSpec as DateColumnSpec, 110 | onFilterConfirm = { columnFilter -> 111 | showFilterSetup = false 112 | showFilterPicker = false 113 | onFilterConfirm(columnFilter) 114 | }, 115 | onClose = { showFilterSetup = false } 116 | ) 117 | is DropdownColumnSpec -> DropdownFilterModal( 118 | selectedColumnSpec as DropdownColumnSpec, 119 | onFilterConfirm = { columnFilter -> 120 | showFilterSetup = false 121 | showFilterPicker = false 122 | onFilterConfirm(columnFilter) 123 | }, 124 | onClose = { showFilterSetup = false } 125 | ) 126 | } 127 | } 128 | 129 | filters.forEach { 130 | InputChip( 131 | true, 132 | modifier = Modifier.padding(end = 8.dp), 133 | onClick = { onRemoveFilter(it) }, 134 | label = { Text(it.label) }, 135 | colors = InputChipDefaults.inputChipColors( 136 | containerColor = Color.Transparent, 137 | selectedContainerColor = Color.Transparent, 138 | labelColor = MaterialTheme.colors.onSurface, 139 | selectedLabelColor = MaterialTheme.colors.onSurface 140 | ), 141 | border = InputChipDefaults.inputChipBorder( 142 | borderColor = Color(0x1f000000), 143 | borderWidth = 1.dp, 144 | selected = false, 145 | enabled = true 146 | ), 147 | trailingIcon = { 148 | IconButton( 149 | modifier = Modifier.size(18.dp), 150 | onClick = { onRemoveFilter(it) } 151 | ) { 152 | Image(imageVector = DataTableIcons.Close, contentDescription = "Filter") 153 | } 154 | } 155 | 156 | ) 157 | } 158 | } 159 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/IntFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.Row 6 | import androidx.compose.foundation.layout.fillMaxWidth 7 | import androidx.compose.foundation.layout.padding 8 | import androidx.compose.foundation.text.KeyboardOptions 9 | import androidx.compose.material.OutlinedTextField 10 | import androidx.compose.material.Text 11 | import androidx.compose.material.TextButton 12 | import androidx.compose.material3.FilledTonalButton 13 | import androidx.compose.runtime.Composable 14 | import androidx.compose.runtime.derivedStateOf 15 | import androidx.compose.runtime.getValue 16 | import androidx.compose.runtime.mutableStateOf 17 | import androidx.compose.runtime.remember 18 | import androidx.compose.runtime.setValue 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.text.input.KeyboardType 21 | import androidx.compose.ui.unit.dp 22 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 23 | import io.github.aleksandar_stefanovic.composematerialdatatable.IntColumnSpec 24 | import io.github.aleksandar_stefanovic.composematerialdatatable.onEnterPress 25 | 26 | @Composable 27 | internal fun IntFilterModal( 28 | columnSpec: IntColumnSpec, 29 | onFilterConfirm: (NumberFilter) -> Unit, 30 | onClose: () -> Unit 31 | ) { 32 | val predicates = listOf( 33 | FilterPredicate.IS, 34 | FilterPredicate.NOT_IS, 35 | FilterPredicate.GREATER_THAN, 36 | FilterPredicate.GREATER_THAN_EQUALS, 37 | FilterPredicate.LESS_THAN, 38 | FilterPredicate.LESS_THAN_EQUALS, 39 | FilterPredicate.BETWEEN 40 | ) 41 | 42 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 43 | 44 | var firstText by remember { mutableStateOf("") } 45 | val firstValue: Int? by remember(firstText) { 46 | derivedStateOf { 47 | firstText.toIntOrNull() 48 | } 49 | } 50 | 51 | var secondText by remember { mutableStateOf("") } 52 | val secondValue: Int? by remember(secondText) { 53 | derivedStateOf { 54 | secondText.toIntOrNull() 55 | } 56 | } 57 | 58 | val canConfirm by remember(selectedPredicate, firstValue, secondValue) { 59 | derivedStateOf { 60 | if (selectedPredicate == FilterPredicate.BETWEEN) { 61 | firstValue != null && secondValue != null 62 | } else { 63 | firstValue != null 64 | } 65 | } 66 | } 67 | 68 | val onConfirm = { 69 | if (canConfirm) { 70 | onFilterConfirm(NumberFilter(columnSpec, selectedPredicate, listOf(firstValue!!, secondValue ?: 0))) 71 | } 72 | } 73 | 74 | Column { 75 | DropdownPicker( 76 | selectedPredicate, 77 | predicates, 78 | valueFormatter = { it.verb }, 79 | onOptionPicked = { selectedPredicate = it } 80 | ) 81 | 82 | Row { 83 | OutlinedTextField( 84 | firstText, 85 | onValueChange = { firstText = it; }, 86 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), 87 | isError = firstValue == null && firstText != "", 88 | modifier = Modifier.onEnterPress(onConfirm), 89 | singleLine = true 90 | ) 91 | 92 | if (selectedPredicate == FilterPredicate.BETWEEN) { 93 | Text(" and ") 94 | OutlinedTextField( 95 | secondText, 96 | onValueChange = { secondText = it; }, 97 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), 98 | isError = secondValue == null && secondText != "", 99 | modifier = Modifier.onEnterPress(onConfirm), 100 | singleLine = true 101 | ) 102 | } 103 | } 104 | 105 | Row( 106 | Modifier.fillMaxWidth().padding(top = 12.dp), 107 | horizontalArrangement = Arrangement.End 108 | ) { 109 | TextButton( 110 | onClose, 111 | Modifier.padding(end = 8.dp) 112 | ) { Text("Cancel") } 113 | FilledTonalButton(onClick = onConfirm, enabled = canConfirm) { Text("Apply") } 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/filter/TextFilterModal.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.filter 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.Row 6 | import androidx.compose.foundation.layout.fillMaxWidth 7 | import androidx.compose.foundation.layout.padding 8 | import androidx.compose.material.OutlinedTextField 9 | import androidx.compose.material.Text 10 | import androidx.compose.material.TextButton 11 | import androidx.compose.material3.FilledTonalButton 12 | import androidx.compose.runtime.Composable 13 | import androidx.compose.runtime.getValue 14 | import androidx.compose.runtime.mutableStateOf 15 | import androidx.compose.runtime.remember 16 | import androidx.compose.runtime.setValue 17 | import androidx.compose.ui.Modifier 18 | import androidx.compose.ui.unit.dp 19 | import io.github.aleksandar_stefanovic.composematerialdatatable.DropdownPicker 20 | import io.github.aleksandar_stefanovic.composematerialdatatable.TextColumnSpec 21 | import io.github.aleksandar_stefanovic.composematerialdatatable.onEnterPress 22 | 23 | @Composable 24 | internal fun TextFilterModal( 25 | columnSpec: TextColumnSpec, 26 | onFilterConfirm: (StringFilter) -> Unit, 27 | onClose: () -> Unit) { 28 | 29 | val predicates = listOf( 30 | FilterPredicate.CONTAINS, 31 | FilterPredicate.NOT_CONTAINS, 32 | FilterPredicate.IS, 33 | FilterPredicate.NOT_IS, 34 | FilterPredicate.STARTS_WITH, 35 | FilterPredicate.ENDS_WITH, 36 | // TODO implement EMPTY, NOT_EMPTY 37 | ) 38 | 39 | var selectedPredicate by remember { mutableStateOf(predicates.first()) } 40 | 41 | Column { 42 | DropdownPicker( 43 | selectedPredicate, 44 | predicates, 45 | valueFormatter = { it.verb }, 46 | onOptionPicked = { selectedPredicate = it } 47 | ) 48 | 49 | var searchTerm by remember { mutableStateOf("") } 50 | 51 | OutlinedTextField( 52 | searchTerm, 53 | onValueChange = { 54 | searchTerm = it 55 | }, 56 | singleLine = true, 57 | modifier = Modifier.onEnterPress { 58 | if (searchTerm.isNotBlank()) { 59 | onFilterConfirm(StringFilter(columnSpec, selectedPredicate, searchTerm)) 60 | } 61 | } 62 | ) 63 | 64 | Row( 65 | Modifier.fillMaxWidth().padding(top = 12.dp), 66 | horizontalArrangement = Arrangement.End 67 | ) { 68 | TextButton( 69 | onClose, 70 | Modifier.padding(end = 8.dp) 71 | ) { Text("Cancel") } 72 | FilledTonalButton(onClick = { 73 | if (searchTerm.isNotBlank()) { 74 | onFilterConfirm(StringFilter(columnSpec, selectedPredicate, searchTerm)) 75 | } 76 | }) { Text("Apply") } 77 | } 78 | 79 | } 80 | } -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/ArrowDownward.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.ArrowDownward: ImageVector 10 | get() { 11 | if (_ArrowDownward != null) { 12 | return _ArrowDownward!! 13 | } 14 | _ArrowDownward = ImageVector.Builder( 15 | name = "ArrowDownward", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveTo(440f, 160f) 24 | verticalLineToRelative(487f) 25 | lineTo(216f, 423f) 26 | lineToRelative(-56f, 57f) 27 | lineToRelative(320f, 320f) 28 | lineToRelative(320f, -320f) 29 | lineToRelative(-56f, -57f) 30 | lineToRelative(-224f, 224f) 31 | verticalLineToRelative(-487f) 32 | horizontalLineToRelative(-80f) 33 | close() 34 | } 35 | }.build() 36 | 37 | return _ArrowDownward!! 38 | } 39 | 40 | @Suppress("ObjectPropertyName") 41 | private var _ArrowDownward: ImageVector? = null 42 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/ArrowUpward.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.ArrowUpward: ImageVector 10 | get() { 11 | if (_ArrowUpward != null) { 12 | return _ArrowUpward!! 13 | } 14 | _ArrowUpward = ImageVector.Builder( 15 | name = "ArrowUpward", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveTo(440f, 800f) 24 | verticalLineToRelative(-487f) 25 | lineTo(216f, 537f) 26 | lineToRelative(-56f, -57f) 27 | lineToRelative(320f, -320f) 28 | lineToRelative(320f, 320f) 29 | lineToRelative(-56f, 57f) 30 | lineToRelative(-224f, -224f) 31 | verticalLineToRelative(487f) 32 | horizontalLineToRelative(-80f) 33 | close() 34 | } 35 | }.build() 36 | 37 | return _ArrowUpward!! 38 | } 39 | 40 | @Suppress("ObjectPropertyName") 41 | private var _ArrowUpward: ImageVector? = null 42 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/ChevronLeft.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.ChevronLeft: ImageVector 10 | get() { 11 | if (_ChevronLeft != null) { 12 | return _ChevronLeft!! 13 | } 14 | _ChevronLeft = ImageVector.Builder( 15 | name = "ChevronLeft", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveTo(560f, 720f) 24 | lineTo(320f, 480f) 25 | lineToRelative(240f, -240f) 26 | lineToRelative(56f, 56f) 27 | lineToRelative(-184f, 184f) 28 | lineToRelative(184f, 184f) 29 | lineToRelative(-56f, 56f) 30 | close() 31 | } 32 | }.build() 33 | 34 | return _ChevronLeft!! 35 | } 36 | 37 | @Suppress("ObjectPropertyName") 38 | private var _ChevronLeft: ImageVector? = null 39 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/ChevronRight.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.ChevronRight: ImageVector 10 | get() { 11 | if (_ChevronRight != null) { 12 | return _ChevronRight!! 13 | } 14 | _ChevronRight = ImageVector.Builder( 15 | name = "ChevronRight", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveTo(504f, 480f) 24 | lineTo(320f, 296f) 25 | lineToRelative(56f, -56f) 26 | lineToRelative(240f, 240f) 27 | lineToRelative(-240f, 240f) 28 | lineToRelative(-56f, -56f) 29 | lineToRelative(184f, -184f) 30 | close() 31 | } 32 | }.build() 33 | 34 | return _ChevronRight!! 35 | } 36 | 37 | @Suppress("ObjectPropertyName") 38 | private var _ChevronRight: ImageVector? = null 39 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/Close.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.group 7 | import androidx.compose.ui.graphics.vector.path 8 | import androidx.compose.ui.unit.dp 9 | 10 | internal val DataTableIcons.Close: ImageVector 11 | get() { 12 | if (_Close != null) { 13 | return _Close!! 14 | } 15 | _Close = ImageVector.Builder( 16 | name = "Close", 17 | defaultWidth = 24.dp, 18 | defaultHeight = 24.dp, 19 | viewportWidth = 960f, 20 | viewportHeight = 960f 21 | ).apply { 22 | group(translationY = 960f) { 23 | path(fill = SolidColor(Color(0xFF5F6368))) { 24 | moveTo(256f, -200f) 25 | lineToRelative(-56f, -56f) 26 | lineToRelative(224f, -224f) 27 | lineToRelative(-224f, -224f) 28 | lineToRelative(56f, -56f) 29 | lineToRelative(224f, 224f) 30 | lineToRelative(224f, -224f) 31 | lineToRelative(56f, 56f) 32 | lineToRelative(-224f, 224f) 33 | lineToRelative(224f, 224f) 34 | lineToRelative(-56f, 56f) 35 | lineToRelative(-224f, -224f) 36 | lineToRelative(-224f, 224f) 37 | close() 38 | } 39 | } 40 | }.build() 41 | 42 | return _Close!! 43 | } 44 | 45 | @Suppress("ObjectPropertyName") 46 | private var _Close: ImageVector? = null 47 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/DataTableIcons.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | internal object DataTableIcons 4 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/DateRange.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.DateRange: ImageVector 10 | get() { 11 | if (_DateRange != null) { 12 | return _DateRange!! 13 | } 14 | _DateRange = ImageVector.Builder( 15 | name = "DateRange", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f 20 | ).apply { 21 | path(fill = SolidColor(Color(0xFF5F6368))) { 22 | moveTo(320f, 560f) 23 | quadToRelative(-17f, 0f, -28.5f, -11.5f) 24 | reflectiveQuadTo(280f, 520f) 25 | quadToRelative(0f, -17f, 11.5f, -28.5f) 26 | reflectiveQuadTo(320f, 480f) 27 | quadToRelative(17f, 0f, 28.5f, 11.5f) 28 | reflectiveQuadTo(360f, 520f) 29 | quadToRelative(0f, 17f, -11.5f, 28.5f) 30 | reflectiveQuadTo(320f, 560f) 31 | close() 32 | moveTo(480f, 560f) 33 | quadToRelative(-17f, 0f, -28.5f, -11.5f) 34 | reflectiveQuadTo(440f, 520f) 35 | quadToRelative(0f, -17f, 11.5f, -28.5f) 36 | reflectiveQuadTo(480f, 480f) 37 | quadToRelative(17f, 0f, 28.5f, 11.5f) 38 | reflectiveQuadTo(520f, 520f) 39 | quadToRelative(0f, 17f, -11.5f, 28.5f) 40 | reflectiveQuadTo(480f, 560f) 41 | close() 42 | moveTo(640f, 560f) 43 | quadToRelative(-17f, 0f, -28.5f, -11.5f) 44 | reflectiveQuadTo(600f, 520f) 45 | quadToRelative(0f, -17f, 11.5f, -28.5f) 46 | reflectiveQuadTo(640f, 480f) 47 | quadToRelative(17f, 0f, 28.5f, 11.5f) 48 | reflectiveQuadTo(680f, 520f) 49 | quadToRelative(0f, 17f, -11.5f, 28.5f) 50 | reflectiveQuadTo(640f, 560f) 51 | close() 52 | moveTo(200f, 880f) 53 | quadToRelative(-33f, 0f, -56.5f, -23.5f) 54 | reflectiveQuadTo(120f, 800f) 55 | verticalLineToRelative(-560f) 56 | quadToRelative(0f, -33f, 23.5f, -56.5f) 57 | reflectiveQuadTo(200f, 160f) 58 | horizontalLineToRelative(40f) 59 | verticalLineToRelative(-80f) 60 | horizontalLineToRelative(80f) 61 | verticalLineToRelative(80f) 62 | horizontalLineToRelative(320f) 63 | verticalLineToRelative(-80f) 64 | horizontalLineToRelative(80f) 65 | verticalLineToRelative(80f) 66 | horizontalLineToRelative(40f) 67 | quadToRelative(33f, 0f, 56.5f, 23.5f) 68 | reflectiveQuadTo(840f, 240f) 69 | verticalLineToRelative(560f) 70 | quadToRelative(0f, 33f, -23.5f, 56.5f) 71 | reflectiveQuadTo(760f, 880f) 72 | lineTo(200f, 880f) 73 | close() 74 | moveTo(200f, 800f) 75 | horizontalLineToRelative(560f) 76 | verticalLineToRelative(-400f) 77 | lineTo(200f, 400f) 78 | verticalLineToRelative(400f) 79 | close() 80 | moveTo(200f, 320f) 81 | horizontalLineToRelative(560f) 82 | verticalLineToRelative(-80f) 83 | lineTo(200f, 240f) 84 | verticalLineToRelative(80f) 85 | close() 86 | moveTo(200f, 320f) 87 | verticalLineToRelative(-80f) 88 | verticalLineToRelative(80f) 89 | close() 90 | } 91 | }.build() 92 | 93 | return _DateRange!! 94 | } 95 | 96 | @Suppress("ObjectPropertyName") 97 | private var _DateRange: ImageVector? = null 98 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/FilterList.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.group 7 | import androidx.compose.ui.graphics.vector.path 8 | import androidx.compose.ui.unit.dp 9 | 10 | internal val DataTableIcons.FilterList: ImageVector 11 | get() { 12 | if (_FilterList != null) { 13 | return _FilterList!! 14 | } 15 | _FilterList = ImageVector.Builder( 16 | name = "FilterList", 17 | defaultWidth = 24.dp, 18 | defaultHeight = 24.dp, 19 | viewportWidth = 960f, 20 | viewportHeight = 960f 21 | ).apply { 22 | group(translationY = 960f) { 23 | path(fill = SolidColor(Color(0xFF5F6368))) { 24 | moveTo(400f, -240f) 25 | verticalLineToRelative(-80f) 26 | horizontalLineToRelative(160f) 27 | verticalLineToRelative(80f) 28 | horizontalLineTo(400f) 29 | close() 30 | moveTo(240f, -440f) 31 | verticalLineToRelative(-80f) 32 | horizontalLineToRelative(480f) 33 | verticalLineToRelative(80f) 34 | horizontalLineTo(240f) 35 | close() 36 | moveTo(120f, -640f) 37 | verticalLineToRelative(-80f) 38 | horizontalLineToRelative(720f) 39 | verticalLineToRelative(80f) 40 | horizontalLineTo(120f) 41 | close() 42 | } 43 | } 44 | }.build() 45 | 46 | return _FilterList!! 47 | } 48 | 49 | @Suppress("ObjectPropertyName") 50 | private var _FilterList: ImageVector? = null 51 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/FirstPage.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.FirstPage: ImageVector 10 | get() { 11 | if (_FirstPage != null) { 12 | return _FirstPage!! 13 | } 14 | _FirstPage = ImageVector.Builder( 15 | name = "FirstPage", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 24f, 19 | viewportHeight = 24f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveTo(18.41f, 16.59f) 24 | lineTo(13.82f, 12f) 25 | lineToRelative(4.59f, -4.59f) 26 | lineTo(17f, 6f) 27 | lineToRelative(-6f, 6f) 28 | lineToRelative(6f, 6f) 29 | close() 30 | moveTo(6f, 6f) 31 | horizontalLineToRelative(2f) 32 | verticalLineToRelative(12f) 33 | horizontalLineTo(6f) 34 | close() 35 | } 36 | }.build() 37 | 38 | return _FirstPage!! 39 | } 40 | 41 | @Suppress("ObjectPropertyName") 42 | private var _FirstPage: ImageVector? = null 43 | -------------------------------------------------------------------------------- /lib/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/icons/LastPage.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable.icons 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.ui.graphics.SolidColor 5 | import androidx.compose.ui.graphics.vector.ImageVector 6 | import androidx.compose.ui.graphics.vector.path 7 | import androidx.compose.ui.unit.dp 8 | 9 | internal val DataTableIcons.LastPage: ImageVector 10 | get() { 11 | if (_LastPage != null) { 12 | return _LastPage!! 13 | } 14 | _LastPage = ImageVector.Builder( 15 | name = "LastPage", 16 | defaultWidth = 24.dp, 17 | defaultHeight = 24.dp, 18 | viewportWidth = 960f, 19 | viewportHeight = 960f, 20 | autoMirror = true 21 | ).apply { 22 | path(fill = SolidColor(Color(0xFF000000))) { 23 | moveToRelative(280f, 720f) 24 | lineToRelative(-56f, -56f) 25 | lineToRelative(184f, -184f) 26 | lineToRelative(-184f, -184f) 27 | lineToRelative(56f, -56f) 28 | lineToRelative(240f, 240f) 29 | lineToRelative(-240f, 240f) 30 | close() 31 | moveTo(640f, 720f) 32 | verticalLineToRelative(-480f) 33 | horizontalLineToRelative(80f) 34 | verticalLineToRelative(480f) 35 | horizontalLineToRelative(-80f) 36 | close() 37 | } 38 | }.build() 39 | 40 | return _LastPage!! 41 | } 42 | 43 | @Suppress("ObjectPropertyName") 44 | private var _LastPage: ImageVector? = null 45 | -------------------------------------------------------------------------------- /lib/src/desktopMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Util.desktop.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | actual fun String.format(int: Int): String = String.format(this, int) 4 | 5 | actual fun String.format(float: Float): String = String.format(this, float) 6 | 7 | actual fun String.format(double: Double): String = String.format(this, double) -------------------------------------------------------------------------------- /lib/src/iosMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Util.ios.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | actual fun String.format(int: Int): String = int.toString() 4 | 5 | actual fun String.format(float: Float): String = float.toString() 6 | 7 | actual fun String.format(double: Double): String = double.toString() -------------------------------------------------------------------------------- /lib/src/wasmJsMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/Util.wasm.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | actual fun String.format(float: Float): String = float.toString() 4 | 5 | actual fun String.format(double: Double): String = double.toString() 6 | 7 | actual fun String.format(int: Int): String = int.toString() 8 | -------------------------------------------------------------------------------- /lib/src/wasmJsMain/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Compose Material Data Table 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /lib/src/wasmJsMain/resources/styles.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | width: 100%; 3 | height: 100%; 4 | margin: 0; 5 | padding: 0; 6 | overflow: hidden; 7 | } -------------------------------------------------------------------------------- /sample/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.compose.desktop.application.dsl.TargetFormat 2 | import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl 3 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 4 | import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig 5 | 6 | plugins { 7 | alias(libs.plugins.kotlinMultiplatform) 8 | alias(libs.plugins.androidApplication) 9 | alias(libs.plugins.composeMultiplatform) 10 | alias(libs.plugins.composeCompiler) 11 | } 12 | 13 | kotlin { 14 | androidTarget { 15 | compilerOptions { 16 | jvmTarget.set(JvmTarget.JVM_11) 17 | } 18 | } 19 | 20 | jvm("desktop") 21 | 22 | listOf( 23 | iosX64(), 24 | iosArm64(), 25 | iosSimulatorArm64() 26 | ).forEach { iosTarget -> 27 | iosTarget.binaries.framework { 28 | baseName = "ComposeMaterialDataTable" 29 | isStatic = true 30 | 31 | export(project(":lib")) 32 | } 33 | } 34 | 35 | @OptIn(ExperimentalWasmDsl::class) 36 | wasmJs { 37 | moduleName = "sample" 38 | browser { 39 | val rootDirPath = project.rootDir.path 40 | val projectDirPath = project.projectDir.path 41 | commonWebpackConfig { 42 | outputFileName = "sample.js" 43 | devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { 44 | static = (static ?: mutableListOf()).apply { 45 | // Serve sources to debug inside browser 46 | add(rootDirPath) 47 | add(projectDirPath) 48 | } 49 | } 50 | } 51 | } 52 | binaries.executable() 53 | } 54 | 55 | sourceSets { 56 | val desktopMain by getting 57 | 58 | androidMain.dependencies { 59 | implementation(compose.preview) 60 | implementation(libs.androidx.activity.compose) 61 | } 62 | commonMain.dependencies { 63 | implementation(compose.runtime) 64 | implementation(compose.foundation) 65 | implementation(compose.material) 66 | implementation(compose.material3) 67 | implementation(compose.ui) 68 | implementation(compose.components.resources) 69 | implementation(compose.components.uiToolingPreview) 70 | implementation(libs.androidx.lifecycle.viewmodel) 71 | implementation(libs.androidx.lifecycle.runtime.compose) 72 | implementation(libs.kotlinx.datetime) 73 | implementation(project(":lib")) 74 | } 75 | desktopMain.dependencies { 76 | implementation(compose.desktop.currentOs) 77 | implementation(libs.kotlinx.coroutines.swing) 78 | } 79 | iosMain.dependencies { 80 | api(project(":lib")) 81 | } 82 | } 83 | } 84 | 85 | android { 86 | namespace = "io.github.aleksandar_stefanovic.composematerialdatatable" 87 | compileSdk = libs.versions.android.compileSdk.get().toInt() 88 | 89 | defaultConfig { 90 | applicationId = "io.github.aleksandar_stefanovic.composematerialdatatable" 91 | minSdk = libs.versions.android.minSdk.get().toInt() 92 | targetSdk = libs.versions.android.targetSdk.get().toInt() 93 | versionCode = 2 94 | versionName = "1.2.1" 95 | } 96 | packaging { 97 | resources { 98 | excludes += "/META-INF/{AL2.0,LGPL2.1}" 99 | } 100 | } 101 | buildTypes { 102 | getByName("release") { 103 | isMinifyEnabled = false 104 | } 105 | } 106 | compileOptions { 107 | sourceCompatibility = JavaVersion.VERSION_11 108 | targetCompatibility = JavaVersion.VERSION_11 109 | } 110 | } 111 | 112 | dependencies { 113 | implementation(project(":lib")) 114 | debugImplementation(compose.uiTooling) 115 | } 116 | 117 | compose.desktop { 118 | application { 119 | mainClass = "io.github.aleksandar_stefanovic.composematerialdatatable.MainKt" 120 | 121 | nativeDistributions { 122 | targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) 123 | packageName = "io.github.aleksandar_stefanovic.composematerialdatatable" 124 | packageVersion = "1.2.1" 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /sample/src/androidMain/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/androidMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.compose.setContent 6 | import androidx.compose.runtime.Composable 7 | import androidx.compose.ui.tooling.preview.Preview 8 | 9 | class MainActivity : ComponentActivity() { 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | 13 | setContent { 14 | App() 15 | } 16 | } 17 | } 18 | 19 | @Preview 20 | @Composable 21 | fun AppAndroidPreview() { 22 | App() 23 | } -------------------------------------------------------------------------------- /sample/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /sample/src/androidMain/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksandar-stefanovic/compose-material-data-table/a16fa40e45667e5be51aa9f8c46589489b7d4c15/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/androidMain/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Compose Material Data Table 3 | -------------------------------------------------------------------------------- /sample/src/commonMain/composeResources/drawable/close.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/commonMain/composeResources/drawable/compose-multiplatform.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 14 | 18 | 24 | 30 | 36 | -------------------------------------------------------------------------------- /sample/src/commonMain/composeResources/drawable/filter-list.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/commonMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/App.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.foundation.layout.Column 4 | import androidx.compose.foundation.layout.padding 5 | import androidx.compose.material.MaterialTheme 6 | import androidx.compose.material.Text 7 | import androidx.compose.runtime.Composable 8 | import androidx.compose.runtime.getValue 9 | import androidx.compose.runtime.mutableStateOf 10 | import androidx.compose.runtime.remember 11 | import androidx.compose.runtime.setValue 12 | import androidx.compose.ui.Modifier 13 | import androidx.compose.ui.unit.dp 14 | import kotlinx.datetime.LocalDate 15 | import org.jetbrains.compose.ui.tooling.preview.Preview 16 | 17 | private enum class Genre(val stringValue: String) { 18 | ACTION("Action"), DRAMA("Drama"), ADVENTURE("Adventure"), 19 | CRIME("Crime"), SCI_FI("Science Fiction") 20 | } 21 | 22 | private data class Movie( 23 | val title: String, 24 | val releaseDate: LocalDate, 25 | val rating: Double, 26 | val genre: Genre, 27 | val watched: Boolean, 28 | val awardCount: Int 29 | ) 30 | 31 | private val movies = listOf( 32 | Movie( 33 | title = "Guardians of the API", 34 | releaseDate = LocalDate(2014, 8, 1), 35 | rating = 8.0, 36 | genre = Genre.ACTION, 37 | watched = true, 38 | awardCount = 52 39 | ), 40 | Movie( 41 | title = "Compose Club", 42 | releaseDate = LocalDate(1999, 10, 15), 43 | rating = 8.8, 44 | genre = Genre.DRAMA, 45 | watched = true, 46 | awardCount = 11 47 | ), 48 | Movie( 49 | title = "Jetpack to the Future", 50 | releaseDate = LocalDate(1985, 7, 3), 51 | rating = 8.5, 52 | genre = Genre.ADVENTURE, 53 | watched = true, 54 | awardCount = 19 55 | ), 56 | Movie( 57 | title = "Runtime Fiction", 58 | releaseDate = LocalDate(1994, 10, 14), 59 | rating = 8.9, 60 | genre = Genre.CRIME, 61 | watched = false, 62 | awardCount = 70 63 | ), 64 | Movie( 65 | title = "The Layout Matrix", 66 | releaseDate = LocalDate(1999, 3, 31), 67 | rating = 8.7, 68 | genre = Genre.SCI_FI, 69 | watched = true, 70 | awardCount = 46 71 | ), 72 | Movie( 73 | title = "Exception: Impossible", 74 | releaseDate = LocalDate(1996, 5, 22), 75 | rating = 7.1, 76 | genre = Genre.ACTION, 77 | watched = false, 78 | awardCount = 11 79 | ) 80 | ) 81 | 82 | 83 | @Composable 84 | @Preview 85 | internal fun App() { 86 | MaterialTheme { 87 | val columnSpecs = listOf>( 88 | TextColumnSpec("Title", WidthSetting.Flex(1f)) { it.title }, 89 | DateColumnSpec("Release Date", WidthSetting.WrapContent, { it.releaseDate }), 90 | DoubleColumnSpec("Rating", WidthSetting.WrapContent, valueSelector = { it.rating }), 91 | IntColumnSpec("Awards", WidthSetting.WrapContent, { it.awardCount }), 92 | DropdownColumnSpec( 93 | "Genre", 94 | WidthSetting.WrapContent, 95 | { it.genre }, 96 | { it.stringValue }, 97 | Genre.entries.toList(), 98 | onChoicePicked = {} 99 | ), 100 | CheckboxColumnSpec("Watched", WidthSetting.WrapContent) { it.watched } 101 | ) 102 | 103 | Column { 104 | var selectedCount by remember { mutableStateOf(0) } 105 | 106 | Table( 107 | columnSpecs, 108 | movies, 109 | modifier = Modifier.padding(20.dp), 110 | showSelectionColumn = true, 111 | onSelectionChange = { list -> selectedCount = list.size } 112 | ) 113 | 114 | if (selectedCount > 0) { 115 | Text("Selected: $selectedCount") 116 | } 117 | 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /sample/src/desktopMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/main.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.ui.window.Window 4 | import androidx.compose.ui.window.application 5 | 6 | fun main() = application { 7 | Window( 8 | onCloseRequest = ::exitApplication, 9 | title = "Compose Material Data Table", 10 | ) { 11 | App() 12 | } 13 | } -------------------------------------------------------------------------------- /sample/src/iosMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/MainViewController.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.ui.window.ComposeUIViewController 4 | 5 | fun MainViewController() = ComposeUIViewController { App() } -------------------------------------------------------------------------------- /sample/src/wasmJsMain/kotlin/io/github/aleksandar_stefanovic/composematerialdatatable/main.kt: -------------------------------------------------------------------------------- 1 | package io.github.aleksandar_stefanovic.composematerialdatatable 2 | 3 | import androidx.compose.ui.ExperimentalComposeUiApi 4 | import androidx.compose.ui.window.ComposeViewport 5 | import kotlinx.browser.document 6 | 7 | @OptIn(ExperimentalComposeUiApi::class) 8 | fun main() { 9 | ComposeViewport(document.body!!) { 10 | App() 11 | } 12 | } -------------------------------------------------------------------------------- /sample/src/wasmJsMain/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Compose Material Data Table 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/wasmJsMain/resources/styles.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | width: 100%; 3 | height: 100%; 4 | margin: 0; 5 | padding: 0; 6 | overflow: hidden; 7 | } -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "composematerialdatatable" 2 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 3 | 4 | pluginManagement { 5 | repositories { 6 | google { 7 | mavenContent { 8 | includeGroupAndSubgroups("androidx") 9 | includeGroupAndSubgroups("com.android") 10 | includeGroupAndSubgroups("com.google") 11 | } 12 | } 13 | mavenCentral() 14 | gradlePluginPortal() 15 | } 16 | } 17 | 18 | dependencyResolutionManagement { 19 | repositories { 20 | google { 21 | mavenContent { 22 | includeGroupAndSubgroups("androidx") 23 | includeGroupAndSubgroups("com.android") 24 | includeGroupAndSubgroups("com.google") 25 | } 26 | } 27 | mavenCentral() 28 | } 29 | } 30 | 31 | include(":lib") 32 | include(":sample") --------------------------------------------------------------------------------