FButtonStyles.inherit constructor

FButtonStyles.inherit({
  1. required FColors colors,
  2. required FTypography typography,
  3. required FStyle style,
  4. required bool touch,
})

Creates a FButtonStyles that inherits its properties.

Implementation

factory FButtonStyles.inherit({
  required FColors colors,
  required FTypography typography,
  required FStyle style,
  required bool touch,
}) {
  final primary = FButtonSizeStyles.inherit(
    typography: typography,
    style: style,
    touch: touch,
    decoration: (radius) => .from(
      ShapeDecoration(
        shape: RoundedSuperellipseBorder(borderRadius: radius),
        color: colors.primary,
      ),
      variants: {
        [.hovered, .pressed]: .shapeDelta(color: colors.hover(colors.primary)),
        //
        [.disabled]: .shapeDelta(color: colors.disable(colors.primary)),
        //
        [.selected]: .shapeDelta(color: colors.hover(colors.primary)),
        [.selected.and(.disabled)]: .shapeDelta(color: colors.disable(colors.hover(colors.primary))),
      },
    ),
    foregroundColor: colors.primaryForeground,
    disabledForegroundColor: colors.disable(colors.primaryForeground),
  );

  return FButtonStyles(
    FVariants(
      primary,
      variants: {
        [.primary]: primary,
        [.secondary]: .inherit(
          typography: typography,
          style: style,
          touch: touch,
          decoration: (radius) => .from(
            ShapeDecoration(
              shape: RoundedSuperellipseBorder(borderRadius: radius),
              color: colors.secondary,
            ),
            variants: {
              [.hovered, .pressed]: .shapeDelta(color: colors.hover(colors.secondary)),
              //
              [.disabled]: .shapeDelta(color: colors.disable(colors.secondary)),
              //
              [.selected]: .shapeDelta(color: colors.hover(colors.secondary)),
              [.selected.and(.disabled)]: .shapeDelta(color: colors.disable(colors.hover(colors.secondary))),
            },
          ),
          foregroundColor: colors.secondaryForeground,
          disabledForegroundColor: colors.disable(colors.secondaryForeground),
        ),
        [.destructive]: .inherit(
          typography: typography,
          style: style,
          touch: touch,
          decoration: (radius) => .from(
            ShapeDecoration(
              shape: RoundedSuperellipseBorder(borderRadius: radius),
              color: colors.destructive.withValues(alpha: colors.brightness == .light ? 0.1 : 0.2),
            ),
            variants: {
              [.hovered, .pressed]: .shapeDelta(
                color: colors.destructive.withValues(alpha: colors.brightness == .light ? 0.2 : 0.3),
              ),
              //
              [.disabled]: .shapeDelta(
                color: colors.destructive.withValues(alpha: colors.brightness == .light ? 0.05 : 0.1),
              ),
              //
              [.selected]: .shapeDelta(
                color: colors.destructive.withValues(alpha: colors.brightness == .light ? 0.2 : 0.3),
              ),
              [.selected.and(.disabled)]: .shapeDelta(
                color: colors.disable(colors.destructive.withValues(alpha: colors.brightness == .light ? 0.2 : 0.3)),
              ),
            },
          ),
          foregroundColor: colors.destructive,
          disabledForegroundColor: colors.destructive.withValues(alpha: 0.5),
        ),
        [.outline]: .inherit(
          typography: typography,
          style: style,
          touch: touch,
          decoration: (radius) => .from(
            ShapeDecoration(
              shape: RoundedSuperellipseBorder(
                side: BorderSide(color: colors.border, width: style.borderWidth),
                borderRadius: radius,
              ),
              color: colors.card,
            ),
            variants: {
              [.hovered, .pressed]: .shapeDelta(color: colors.secondary),
              //
              [.disabled]: .shapeDelta(color: colors.disable(colors.card)),
              //
              [.selected]: .shapeDelta(color: colors.secondary),
              [.selected.and(.disabled)]: .shapeDelta(color: colors.disable(colors.secondary)),
            },
          ),
          foregroundColor: colors.secondaryForeground,
          disabledForegroundColor: colors.disable(colors.secondaryForeground),
        ),
        [.ghost]: .inherit(
          typography: typography,
          style: style,
          touch: touch,
          decoration: (radius) => .from(
            ShapeDecoration(shape: RoundedSuperellipseBorder(borderRadius: radius)),
            variants: {
              [.hovered, .pressed]: .shapeDelta(color: colors.secondary),
              //
              [.disabled]: const .shapeDelta(),
              //
              [.selected]: .shapeDelta(color: colors.secondary),
              [.selected.and(.disabled)]: .shapeDelta(color: colors.disable(colors.secondary)),
            },
          ),
          foregroundColor: colors.secondaryForeground,
          disabledForegroundColor: colors.disable(colors.secondaryForeground),
        ),
      },
    ),
  );
}