mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[compose] Introduce internal Compose Showcase action with basic some jewel components
GitOrigin-RevId: 8bf7f8ba3279f360843c61b64c95626793798699
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3a2260f613
commit
d956ba446e
@@ -208,5 +208,6 @@
|
||||
<orderEntry type="module" module-name="intellij.xml.xmlbeans" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.jsonpath" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.newUiOnboarding" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="intellij.platform.compose" scope="RUNTIME" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -26,6 +26,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
||||
6
platform/compose/resources/META-INF/compose.xml
Normal file
6
platform/compose/resources/META-INF/compose.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<idea-plugin>
|
||||
<actions>
|
||||
<action id="ComposeShowcaseAction" internal="true" class="com.intellij.compose.showcase.ComposeShowcaseAction"
|
||||
text="Compose Components Showcase"/>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,142 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compose.showcase
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.jetbrains.jewel.*
|
||||
|
||||
@Composable
|
||||
internal fun ComposeShowcase() {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(15.dp),
|
||||
modifier = Modifier.padding(10.dp)
|
||||
) {
|
||||
CheckBox()
|
||||
RadioButton()
|
||||
Button()
|
||||
Label()
|
||||
Tabs()
|
||||
LinkLabels()
|
||||
TextField()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
private fun CheckBox() {
|
||||
var checkedState by remember { mutableStateOf(false) }
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
Text("Checkbox:")
|
||||
CheckboxRow(
|
||||
"checkBox",
|
||||
checkedState,
|
||||
LocalResourceLoader.current,
|
||||
onCheckedChange = {
|
||||
checkedState = it
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
private fun RadioButton() {
|
||||
var selectedRadioButton by remember { mutableStateOf(1) }
|
||||
val resourceLoader = LocalResourceLoader.current
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
Text("radioButton")
|
||||
RadioButtonRow(
|
||||
"Value 1",
|
||||
selected = selectedRadioButton == 0,
|
||||
resourceLoader,
|
||||
onClick = {
|
||||
selectedRadioButton = 0
|
||||
}
|
||||
)
|
||||
RadioButtonRow(
|
||||
"Value 2",
|
||||
selected = selectedRadioButton == 1,
|
||||
resourceLoader,
|
||||
onClick = {
|
||||
selectedRadioButton = 1
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Label() {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
Text("label:")
|
||||
Text("Some label")
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Button() {
|
||||
OutlinedButton(onClick = {
|
||||
// no nothing
|
||||
}) {
|
||||
Text("button")
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Tabs() {
|
||||
var selectedTabIndex by remember { mutableStateOf(0) }
|
||||
val tabIds by remember { mutableStateOf((1..12).toList()) }
|
||||
|
||||
val tabs by derivedStateOf {
|
||||
tabIds.mapIndexed { index, id ->
|
||||
TabData.Default(
|
||||
selected = index == selectedTabIndex,
|
||||
label = "Tab $id",
|
||||
closable = false,
|
||||
onClick = { selectedTabIndex = index },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
TabStrip(tabs)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
private fun LinkLabels() {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
val resourceLoader = LocalResourceLoader.current
|
||||
|
||||
Text("Labels:")
|
||||
Link("Link", resourceLoader, onClick = {
|
||||
// do nothing
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TextField() {
|
||||
var textFieldState by remember { mutableStateOf("") }
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
Text("Text field:")
|
||||
TextField(textFieldState, onValueChange = {
|
||||
textFieldState = it
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compose.showcase
|
||||
|
||||
import com.intellij.compose.JBComposePanel
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.DialogWrapper
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.ui.PaintingParent.Wrapper
|
||||
import java.awt.Dimension
|
||||
import javax.swing.JComponent
|
||||
|
||||
private fun createComposeShowcaseComponent(): JComponent {
|
||||
return JBComposePanel {
|
||||
ComposeShowcase()
|
||||
}
|
||||
}
|
||||
|
||||
private class ComposeShowcaseAction : DumbAwareAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ComposeShowcaseDialog(e.project, e.presentation.text).show()
|
||||
}
|
||||
}
|
||||
|
||||
private class ComposeShowcaseDialog(project: Project?, @NlsSafe dialogTitle: String) :
|
||||
DialogWrapper(project, null, true, IdeModalityType.MODELESS, false) {
|
||||
|
||||
init {
|
||||
title = dialogTitle
|
||||
init()
|
||||
}
|
||||
|
||||
override fun createCenterPanel(): JComponent {
|
||||
return Wrapper(createComposeShowcaseComponent()).apply {
|
||||
minimumSize = Dimension(200, 100)
|
||||
preferredSize = Dimension(800, 600)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,10 @@
|
||||
<xi:fallback/>
|
||||
</xi:include>
|
||||
|
||||
<xi:include href="/META-INF/compose.xml">
|
||||
<xi:fallback/>
|
||||
</xi:include>
|
||||
|
||||
<xi:include href="/META-INF/ml.xml">
|
||||
<xi:fallback/>
|
||||
</xi:include>
|
||||
|
||||
Reference in New Issue
Block a user