Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(design toolbox): display code implementation for each component #343

Draft
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

florentmaitre
Copy link
Member

No description provided.

Copy link

github-actions bot commented Feb 12, 2025

@florentmaitre florentmaitre marked this pull request as draft February 12, 2025 14:33
@florentmaitre florentmaitre force-pushed the 248-display-code-implementation-for-each-component branch from 752d732 to ed5e392 Compare February 12, 2025 15:07
@florentmaitre florentmaitre marked this pull request as ready for review February 12, 2025 15:11
@florentmaitre florentmaitre changed the title chore: display code implementation for each component feat(design toolbox): display code implementation for each component Feb 12, 2025

private val CODE_INDENT = " "

interface CodeFormattable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename it to FormattableCode?

@DslMarker
annotation class CodeDslMarker

private val CODE_INDENT = " "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add const as suggested by AS


fun Code.Builder.coloredBoxCall(onColoredBox: Boolean, content: Code.Builder.() -> Unit) {
if (onColoredBox) {
functionCall("OudsColoredBox") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace "OudsColoredBox" by OudsColoredBox.javaClass.simpleName which seems safer if we rename it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we can't use Composable methods references but I did not realize that we could use the associated object, that's a good idea 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this won't work with OudsCheckbox because the associated object is internal.

state = this@DemoScreen,
modifier = Modifier
.padding(all = OudsTheme.spaces.fixed.medium)
.padding(top = OudsTheme.spaces.fixed.medium)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this line?

Copy link
Member Author

@florentmaitre florentmaitre Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it matches the Figma and I thought it was easier to read than setting three paddings (horizontal, bottom and top):

Capture d’écran 2025-02-14 à 11 13 35

But we can change how it's written if you prefer the other way. Or move the second top padding to the bottom padding of the ButtonDemo.

val text = stringResource(id = R.string.app_components_button_label)
CodeSnippet(modifier = modifier) {
coloredBoxCall(state.onColoredBox) {
functionCall("OudsButton") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as before, should we use OudsButton.javaClass.simpleName?

functionCall("OudsButton") {
if (state.layout in listOf(ButtonDemoState.Layout.IconOnly, ButtonDemoState.Layout.IconAndText)) {
constructorCallArgument<OudsButton.Icon>("icon") {
functionCallArgument("painter", "painterResource") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we define constants for function names like painterResource, stringResource`, ...?

state = this@DemoScreen,
modifier = Modifier
.padding(all = OudsTheme.spaces.fixed.medium)
.padding(top = OudsTheme.spaces.fixed.medium)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, do we need this line?


override fun format(context: Context): String {
val valueString = when (value) {
is Float -> "${value}F"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Float is more represented with a lower case f no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought too. But if you write val a: Float = 1.0, then Android Studio suggests to change this code to val a: Float = 1.0F.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display code implementation for each component
2 participants