Skip to content

Commit 6b39fc5

Browse files
authored
Merge pull request #110 from compose-fluent/doc
feat: Documents.
2 parents 4361954 + b850672 commit 6b39fc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4606
-32
lines changed

fluent/src/commonMain/kotlin/io/github/composefluent/Colors.kt

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.

fluent/src/commonMain/kotlin/io/github/composefluent/ExperimentalFluentApi.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package io.github.jpy.wangposefluent
22

3+
/**
4+
* Marks declarations that are part of an experimental fluent API.
5+
*
6+
* Experimental fluent APIs are subject to change or removal in future releases.
7+
* The design and structure of these APIs are not considered stable, and breaking
8+
* changes may occur without a major version increment.
9+
*
10+
* Using elements marked with this annotation requires explicit opt-in, either by
11+
* applying the `@OptIn(ExperimentalFluentApi::class)` annotation to the calling site
12+
* or by enabling the `-opt-in=io.github.jpy.wangposefluent.ExperimentalFluentApi` compiler
13+
* argument.
14+
*
15+
* **Warning:** Use of experimental fluent APIs should be carefully considered, as
16+
* they might introduce unforeseen compatibility issues or unexpected behavior changes
17+
* when updating to newer versions of the library.
18+
*/
319
@RequiresOptIn(message = "This is an experimental fluent API.")
420
@Target(
521
AnnotationTarget.CLASS,

fluent/src/commonMain/kotlin/io/github/composefluent/FluentTheme.kt

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ import io.github.jpy.wangposefluent.component.ContentDialogHostState
1919
import io.github.jpy.wangposefluent.component.LocalContentDialog
2020
import io.github.jpy.wangposefluent.component.ProvideFontIcon
2121

22+
/**
23+
* FluentTheme is the root component of the Fluent Design System for Compose.
24+
* It provides the default theming values and a [MaterialContainer] for acrylic effects.
25+
* **Note:** This function is designed to be placed inside a Window or View. For global
26+
* theme configuration, consider using [FluentThemeConfiguration].
27+
*
28+
* @param colors The colors to use for the theme. Defaults to [FluentTheme.colors].
29+
* @param typography The typography to use for the theme. Defaults to [FluentTheme.typography].
30+
* @param cornerRadius The corner radius to use for the theme. Defaults to [FluentTheme.cornerRadius].
31+
* @param useAcrylicPopup Whether to use acrylic for popups. Defaults to [LocalAcrylicPopupEnabled.current].
32+
* @param compactMode Whether to use compact mode. Defaults to true.
33+
* @param content The content to display within the theme.
34+
*/
2235
@ExperimentalFluentApi
2336
@Composable
2437
fun FluentTheme(
@@ -56,7 +69,19 @@ fun FluentTheme(
5669
}
5770

5871
/**
59-
* Uses for override theme configuration
72+
* Overrides individual theme configuration options for a subset of the UI tree.
73+
*
74+
* This allows you to locally modify aspects of the theme, such as colors, typography,
75+
* corner radius, compact mode, and whether acrylic popups are used,
76+
* for the components within the provided `content`.
77+
*
78+
* @param colors The colors to use for this configuration scope. Defaults to the current [FluentTheme.colors].
79+
* @param typography The typography to use for this configuration scope. Defaults to the current [FluentTheme.typography].
80+
* @param cornerRadius The corner radius values to use for this configuration scope. Defaults to the current [FluentTheme.cornerRadius].
81+
* @param useAcrylicPopup Whether to use acrylic for popups within this configuration scope. Defaults to the current value of [LocalAcrylicPopupEnabled].
82+
* @param compactMode Whether compact mode is enabled within this configuration scope. Defaults to the current value of [LocalCompactMode].
83+
* @param contentDialogHostState The state of the content dialog host to use for this configuration scope. Defaults to the current value of [LocalContentDialog].
84+
* @param content The composable content that will inherit the specified theme configuration.
6085
*/
6186
@ExperimentalFluentApi
6287
@Composable
@@ -85,6 +110,14 @@ fun FluentThemeConfiguration(
85110
)
86111
}
87112

113+
/**
114+
* FluentTheme provides a default theme for your application using the Fluent Design System.
115+
* It applies default colors and typography, and enables compact mode.
116+
*
117+
* @param colors The colors to use for the theme. Defaults to the current FluentTheme colors.
118+
* @param typography The typography to use for the theme. Defaults to the current FluentTheme typography.
119+
* @param content The composable content to be themed.
120+
*/
88121
@OptIn(ExperimentalFluentApi::class)
89122
@Composable
90123
fun FluentTheme(
@@ -95,6 +128,16 @@ fun FluentTheme(
95128
FluentTheme(colors, typography, LocalCornerRadius.current, useAcrylicPopup = false, compactMode = true, content)
96129
}
97130

131+
/**
132+
* A composable that provides a compact mode configuration for its content.
133+
*
134+
* This function wraps the provided content within a [CompositionLocalProvider] that sets the
135+
* [LocalCompactMode] to the specified [enabled] value. This allows components within the
136+
* [content] to react to the compact mode setting and adjust their appearance or behavior accordingly.
137+
*
138+
* @param enabled Whether compact mode should be enabled for the wrapped content. Defaults to `true`.
139+
* @param content The composable content that should be provided with the compact mode setting.
140+
*/
98141
@Composable
99142
fun CompactMode(enabled: Boolean = true, content: @Composable () -> Unit) {
100143
CompositionLocalProvider(
@@ -103,22 +146,38 @@ fun CompactMode(enabled: Boolean = true, content: @Composable () -> Unit) {
103146
)
104147
}
105148

149+
/**
150+
* Helper object to access the current Fluent Theme properties in a type-safe way.
151+
*/
106152
object FluentTheme {
153+
154+
/**
155+
* The current [Colors] provided by the [FluentTheme].
156+
*/
107157
val colors: Colors
108158
@Composable
109159
@ReadOnlyComposable
110160
get() = LocalColors.current
111161

162+
/**
163+
* The typography used by the theme.
164+
*/
112165
val typography: Typography
113166
@Composable
114167
@ReadOnlyComposable
115168
get() = LocalTypography.current
116169

170+
/**
171+
* CompositionLocal for the current [Shapes]
172+
*/
117173
val shapes: Shapes
118174
@Composable
119175
@ReadOnlyComposable
120176
get() = LocalShapes.current
121177

178+
/**
179+
* Represents the corner radius values for various components in the theme.
180+
*/
122181
val cornerRadius: CornerRadius
123182
@Composable
124183
@ReadOnlyComposable
@@ -154,5 +213,19 @@ private class EmptyMaterialContainerScope : MaterialContainerScope {
154213

155214
internal val LocalAcrylicPopupEnabled = staticCompositionLocalOf { true }
156215

216+
/**
217+
* Creates a Fluent light theme color scheme.
218+
*
219+
* @param accent The accent color to be used for generating the color scheme. Defaults to a specific blue color (0xFF0078D4).
220+
* @return A [Colors] object representing the light theme color scheme.
221+
*/
157222
fun lightColors(accent: Color = Color(0xFF0078D4)): Colors = Colors(generateShades(accent), false)
223+
224+
225+
/**
226+
* Creates a Fluent dark theme color scheme.
227+
*
228+
* @param accent The accent color to be used for generating the color scheme. Defaults to a specific blue color (0xFF0078D4).
229+
* @return A [Colors] object representing the dark theme color scheme.
230+
*/
158231
fun darkColors(accent: Color = Color(0xFF0078D4)): Colors = Colors(generateShades(accent), true)

fluent/src/commonMain/kotlin/io/github/composefluent/Geometry.kt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,40 @@ import androidx.compose.ui.graphics.Shape
88
import androidx.compose.ui.unit.Dp
99
import androidx.compose.ui.unit.dp
1010

11-
/** https://learn.microsoft.com/en-us/windows/apps/design/signature-experiences/geometry */
12-
13-
/** align Shape and CornerRadius style properties */
11+
/**
12+
* Aligns style properties related to geometry, such as [Shape] and [CornerRadius].
13+
*
14+
* This interface serves as a common structure for defining geometric properties
15+
* across different types of visual elements within a UI. It provides a consistent
16+
* way to access geometry settings for different design use cases:
17+
* - [overlay]: Geometry for elements that appear above other content, such as dialogs or flyouts.
18+
* - [control]: Geometry for interactive controls, such as buttons, text fields, or checkboxes.
19+
* - [intersectionEdge]: Geometry for elements at the intersection of other elements,
20+
* typically used for visual separation or emphasis at boundaries.
21+
*
22+
* The type parameter [Type] allows this interface to be used with different data types
23+
* representing geometric properties, such as [Shape] or [Dp] for corner radius.
24+
*
25+
* Based on the Microsoft Fluent Design System principles for geometry:
26+
* See [https://learn.microsoft.com/en-us/windows/apps/design/signature-experiences/geometry]
27+
*/
1428
interface Geometry<Type> {
1529
val overlay: Type
1630
val control: Type
1731
val intersectionEdge: Type
1832
}
1933

34+
/**
35+
* Defines the shapes used for different elements in the Fluent design system.
36+
*
37+
* This class aligns with the principles described in the Microsoft documentation on Geometry.
38+
* See [https://learn.microsoft.com/en-us/windows/apps/design/signature-experiences/geometry]
39+
* for more details.
40+
*
41+
* @property overlay The shape used for elements like overlays.
42+
* @property control The shape used for control elements like buttons and text fields.
43+
* @property intersectionEdge The shape used for elements at the intersection edge.
44+
*/
2045
@Immutable
2146
class Shapes(
2247
override val overlay: Shape,
@@ -40,6 +65,14 @@ internal fun createShape(cornerRadius: Dp): Shape {
4065
}
4166
}
4267

68+
/**
69+
* Converts a [CornerRadius] object to a [Shapes] object.
70+
*
71+
* This function maps the overlay, control, and intersection edge [Dp] values from the [CornerRadius]
72+
* to corresponding [Shape] objects using the [createShape] function.
73+
*
74+
* @return A [Shapes] object representing the corner radius as shapes.
75+
*/
4376
fun CornerRadius.toShapes(): Shapes {
4477
return Shapes(
4578
overlay = createShape(overlay),
@@ -48,6 +81,16 @@ fun CornerRadius.toShapes(): Shapes {
4881
)
4982
}
5083

84+
/**
85+
* Corner radius values for different geometric elements in the UI.
86+
*
87+
* These values are based on the Microsoft Fluent design system's guidance on geometry.
88+
* https://learn.microsoft.com/en-us/windows/apps/design/signature-experiences/geometry
89+
*
90+
* @property overlay The corner radius for overlay elements.
91+
* @property control The corner radius for control elements.
92+
* @property intersectionEdge The corner radius for elements at intersection edges.
93+
*/
5194
@Immutable
5295
class CornerRadius(
5396
override val overlay: Dp,

fluent/src/commonMain/kotlin/io/github/composefluent/LocalContentAlpha.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ package io.github.jpy.wangposefluent
22

33
import androidx.compose.runtime.compositionLocalOf
44

5+
/**
6+
* CompositionLocal used to pass the default content alpha down the tree.
7+
*
8+
* This is used to provide a default alpha for text, icons and other content that can
9+
* be changed by a parent component.
10+
*/
511
val LocalContentAlpha = compositionLocalOf { 1f }

fluent/src/commonMain/kotlin/io/github/composefluent/LocalContentColor.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ package io.github.jpy.wangposefluent
33
import androidx.compose.runtime.compositionLocalOf
44
import androidx.compose.ui.graphics.Color
55

6+
/**
7+
* CompositionLocal to pass the content color down the tree. For example, a `Button` may provide
8+
* a default content color for the text and iconography inside it.
9+
*
10+
* This is typically used with the alpha applied to the color to provide a useful default for
11+
* text and iconography.
12+
*/
613
val LocalContentColor = compositionLocalOf { Color.Unspecified }

fluent/src/commonMain/kotlin/io/github/composefluent/Typography.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ internal val LocalTypography = staticCompositionLocalOf {
4444
}
4545

4646
/**
47+
* The Fluent Design typography system, providing a set of predefined text styles.
48+
*
49+
* Based on the guidelines from Microsoft's Fluent Design documentation:
4750
* https://docs.microsoft.com/en-us/windows/apps/design/signature-experiences/typography
51+
*
52+
* @property caption Style for smaller text, often used for labels or annotations.
53+
* @property body Standard body text style.
54+
* @property bodyStrong Bold version of the standard body text style.
55+
* @property bodyLarge Larger version of the standard body text style.
56+
* @property subtitle Style for subtitles or secondary headings.
57+
* @property title Style for main titles.
58+
* @property titleLarge Style for large titles, suitable for prominent headings.
59+
* @property display Style for very large text, often used for headlines or displays.
4860
*/
4961
@Immutable
5062
class Typography(
@@ -58,8 +70,19 @@ class Typography(
5870
val display: TextStyle
5971
)
6072

73+
/**
74+
* CompositionLocal containing the current [TextStyle] for text components.
75+
*/
6176
val LocalTextStyle = compositionLocalOf(structuralEqualityPolicy()) { TextStyle.Default }
6277

78+
/**
79+
* This composable provides a [TextStyle] to the composition local tree.
80+
* Any text composables within the `content` lambda will use this provided text style.
81+
* The provided [value] is merged with the current [LocalTextStyle].
82+
*
83+
* @param value The [TextStyle] to provide. This will be merged with the current [LocalTextStyle].
84+
* @param content The composable content that will inherit the provided [TextStyle].
85+
*/
6386
@Composable
6487
fun ProvideTextStyle(value: TextStyle, content: @Composable () -> Unit) {
6588
val mergedStyle = LocalTextStyle.current.merge(value)

fluent/src/commonMain/kotlin/io/github/composefluent/background/Elevation.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ import androidx.compose.ui.unit.Dp
2020
import androidx.compose.ui.unit.dp
2121
import io.github.jpy.wangposefluent.FluentTheme
2222

23+
/**
24+
* Applies an elevation effect to the composable.
25+
*
26+
* This function provides a way to add depth and visual hierarchy to UI elements.
27+
* It uses different approaches based on the elevation value.
28+
*
29+
* When the elevation is less than 1dp, no elevation is applied.
30+
* When the elevation is between 1dp and 3dp, a border with a color from the theme is applied.
31+
* - If the elevation is between 1dp and 2dp, a `SolidColor` is used for the border.
32+
* - If the elevation is between 2dp and 3dp, a provided [strokeShadow] brush is used for the border.
33+
* For elevation of 3dp or more, a more complex shadow effect using [platformElevation] is applied.
34+
*
35+
* @param elevation The desired elevation (depth) of the composable.
36+
* @param shape The shape of the composable, which affects how the shadow is drawn.
37+
* @param strokeShadow The brush to use for the border when elevation is between 2dp and 3dp.
38+
* It defaults to `FluentTheme.colors.borders.circle` if shape is [CircleShape] otherwise `FluentTheme.colors.borders.control`.
39+
* @param isDarkTheme A boolean indicating if dark mode is active, which influences the shadow color.
40+
* Defaults to `FluentTheme.colors.darkMode`.
41+
* @return A [Modifier] that applies the elevation effect.
42+
*/
2343
@Composable
2444
fun Modifier.elevation(
2545
elevation: Dp,
@@ -132,6 +152,23 @@ internal fun Modifier.platformElevation(
132152
}
133153
}
134154

155+
/**
156+
* Default elevation values for different UI components.
157+
*
158+
* These values represent the recommended elevation levels for various elements
159+
* in a Fluent Design system. Elevation is used to create a sense of depth and
160+
* hierarchy in the UI.
161+
*
162+
* The higher the elevation, the more prominent the element appears to be,
163+
* as if it's closer to the user's eye.
164+
*
165+
* - `layer`: Elevation for a basic background layer. Represents no elevation.
166+
* - `control`: Elevation for interactive controls like buttons and toggles.
167+
* - `cardRest`: Elevation for resting cards.
168+
* - `tooltip`: Elevation for tooltips.
169+
* - `flyout`: Elevation for flyout menus.
170+
* - `dialog`: Elevation for modal dialogs, representing the highest level of prominence.
171+
*/
135172
object ElevationDefaults {
136173
val layer: Dp = 0.dp
137174
val control: Dp = 2.dp

fluent/src/commonMain/kotlin/io/github/composefluent/background/Layer.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ fun Layer(
7979
)
8080
}
8181

82+
/**
83+
* A composable that provides a layered background with customizable shape, color, border, and elevation.
84+
*
85+
* @param modifier The [Modifier] to be applied to the layer.
86+
* @param shape The [Shape] of the layer's background. Defaults to [FluentTheme.shapes.control].
87+
* @param color The background [Color] of the layer. Defaults to [FluentTheme.colors.background.layer.default].
88+
* @param contentColor The preferred [Color] for content inside this layer. Defaults to [FluentTheme.colors.text.text.primary].
89+
* @param border The [BorderStroke] to draw around the layer. If null, no border will be drawn. Defaults to a 1.dp border with [FluentTheme.colors.stroke.card.default].
90+
* @param backgroundSizing Specifies how the background extends in relation to the border. See [BackgroundSizing] for options. Defaults to [BackgroundSizing.OuterBorderEdge].
91+
* @param elevation The elevation of the layer, which affects the shadow. Defaults to 0.dp.
92+
* @param content The composable content to be placed inside the layer.
93+
*/
8294
@Composable
8395
fun Layer(
8496
modifier: Modifier = Modifier,
@@ -103,6 +115,19 @@ fun Layer(
103115
)
104116
}
105117

118+
/**
119+
* A composable that provides a background layer with customizable shape, color, border, and elevation.
120+
*
121+
* @param modifier The [Modifier] to be applied to the layer.
122+
* @param shape The [Shape] of the layer's background. Defaults to `FluentTheme.shapes.control`.
123+
* @param color The background [Color] of the layer. Defaults to `FluentTheme.colors.background.layer.default`.
124+
* @param contentColor The default color for the content inside the layer. Defaults to `FluentTheme.colors.text.text.primary`.
125+
* @param border An optional [BorderStroke] to be drawn around the layer's background. Defaults to a 1.dp solid border using `FluentTheme.colors.stroke.card.default`.
126+
* @param backgroundSizing Determines how the background extends in relation to the border. Defaults to [BackgroundSizing.OuterBorderEdge].
127+
* @param clipContent If `true`, the content will be clipped to the layer's shape. Defaults to `false`.
128+
* @param elevation The elevation of the layer, used for shadow effects. Defaults to `0.dp`.
129+
* @param content The content to be displayed within the layer.
130+
*/
106131
@Composable
107132
fun Layer(
108133
modifier: Modifier = Modifier,

0 commit comments

Comments
 (0)