Skip to content

Commit

Permalink
Make Android's SemanticColors file contain a simpler data class. (#84)
Browse files Browse the repository at this point in the history
Also, make sure the generated Android files contain a warning header so they're not modified.
  • Loading branch information
jmartinesp authored Jun 28, 2024
1 parent ee52b30 commit 15f2f1a
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 475 deletions.
8 changes: 8 additions & 0 deletions assets/android/src/CompoundIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
* limitations under the License.
*/

/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
package io.element.android.compound.tokens.generated
Expand Down
510 changes: 81 additions & 429 deletions assets/android/src/SemanticColors.kt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions assets/android/src/TypographyTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
* limitations under the License.
*/

/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
package io.element.android.compound.tokens.generated
Expand Down
7 changes: 7 additions & 0 deletions assets/android/src/internal/DarkColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
Expand Down
7 changes: 7 additions & 0 deletions assets/android/src/internal/DarkHcColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
Expand Down
7 changes: 7 additions & 0 deletions assets/android/src/internal/LightColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
Expand Down
7 changes: 7 additions & 0 deletions assets/android/src/internal/LightHcColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* !!! WARNING !!!
*
* THIS IS AN AUTOGENERATED FILE.
* DO NOT EDIT MANUALLY.
*/



@file:Suppress("all")
Expand Down
3 changes: 2 additions & 1 deletion src/configs/getAndroidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function composeIcons(args: FormatterArguments) {
}

let defaultOptions: Options = {
showFileHeader: false,
showFileHeader: true,
fileHeader: () => ['!!! WARNING !!!', '', 'THIS IS AN AUTOGENERATED FILE.', 'DO NOT EDIT MANUALLY.'],
license: composeAndroidLicense(),
indentLevel: ANDROID_INDENT_LEVEL,
isInternal: false,
Expand Down
2 changes: 1 addition & 1 deletion src/formats/templates/compose/core-colors.kt.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= options.license ?? '' %>
<%= fileHeader({file, commentStyle: 'short'}) %>
<%= fileHeader({file, commentStyle: 'long'}) %>

@file:Suppress("all")
package <%= file.packageName %>
Expand Down
54 changes: 12 additions & 42 deletions src/formats/templates/compose/extra-colors.kt.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
@file:Suppress("all")
package <%= file.packageName %>

import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
<%= options.import.map(function(item) {
return 'import ' + item
}).join('\n') %>

<%= fileHeader({file, commentStyle: 'short'}) %>
<%= fileHeader({file, commentStyle: 'long'}) %>
<%
let colors = allProperties.map(function(prop) {
return { name: options.fixColorName(prop.name), description: prop.description };
Expand All @@ -24,43 +21,16 @@ import androidx.compose.ui.graphics.Color
/**
* This class holds all the semantic tokens of the Compound theme.
*/
@Stable
class <%= file.className %>(
@Immutable
data class <%= file.className %>(
<%= colors.map(function(color) {
return INDENT_LEVEL + color.name + ': Color,'
}).join('\n')
%>
isLight: Boolean,
) {
var isLight by mutableStateOf(isLight)
private set
<%= colors.map(function(color) {
let comment = "";
if (color.description) {
comment = INDENT_LEVEL + `/** ${color.description} */\n`
}
return comment + INDENT_LEVEL + 'var ' + color.name + ' by mutableStateOf(' + color.name + ')\n' + INDENT_2_LEVELS + 'private set'
}).join('\n' ) %>

fun copy(
<%= colors.map(function(color) {
return INDENT_2_LEVELS + color.name + ': Color = this.' + color.name + ','
}).join('\n')
%>
isLight: Boolean = this.isLight,
) = <%= file.className %>(
<%= colors.map(function(color) {
return INDENT_2_LEVELS + color.name + ' = ' + color.name + ','
let comment = "";
if (color.description) {
comment = INDENT_LEVEL + `/** ${color.description} */\n`
}
return comment + INDENT_LEVEL + 'val ' + color.name + ': Color,'
}).join('\n')
%>
isLight = isLight,
)

fun updateColorsFrom(other: <%= file.className %>) {
<%= colors.map(function(color) {
return INDENT_2_LEVELS + color.name + ' = other.' + color.name
}).join('\n')
%>
isLight = other.isLight
}
}
/** True for light theme, false for dark theme. */
val isLight: Boolean,
)
3 changes: 2 additions & 1 deletion src/formats/templates/compose/icons.kt.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= options.license ?? '' %>
<%= fileHeader({file, commentStyle: 'short'}) %>

<%= fileHeader({file, commentStyle: 'long'}) %>

@file:Suppress("all")
package <%= file.packageName %>
Expand Down
3 changes: 2 additions & 1 deletion src/formats/templates/compose/internal-object.kt.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= options.license ?? '' %>
<%= fileHeader({file, commentStyle: 'short'}) %>

<%= fileHeader({file, commentStyle: 'long'}) %>

@file:Suppress("all")
package <%= file.packageName %>
Expand Down

0 comments on commit 15f2f1a

Please sign in to comment.