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

Add MrkDwn component #97

Merged
merged 20 commits into from
Jan 10, 2020
Merged

Add MrkDwn component #97

merged 20 commits into from
Jan 10, 2020

Conversation

javaPhil
Copy link
Contributor

@javaPhil javaPhil commented Dec 17, 2019

Resolves #73

Added <MrkDwn> component and added logic to <Section> and <Context> blocks to handle <MrkDwn> component.

You can now use <MrkDwn> in a <Section> block

<Block>
  <Section>
    <MrkDwn verbatim={false}>
      Hello @user!
    </MrkDwn>
  </Section>
</Block>

which converts to

[{
  type: 'section',
  text: { type: 'mrkdwn', text: 'Hello!', verbatim: false }
}]

or a <Context> block

<Blocks>
  <Context>
    <MrkDwn verbatim={false}>
      Hello @user
    </MrkDwn>
    Welcome
  </Context>
</Blocks>

which converts to

[{
  type: 'context',
  elements: [
    {type: 'mrkdwn', text: 'Hello', verbatim: false},
    {type: 'mrkdwn', text: 'World', verbatim: true}
  ]
}]

@yhatt
Copy link
Owner

yhatt commented Dec 17, 2019

CI looks like failing by incorrect format. Could you execute yarn format --write?

src/block-kit/MrkDwn.tsx Outdated Show resolved Hide resolved
@@ -239,6 +239,24 @@ If you want to use `<Input>` as layout block, you have to place one of [availabl

`<Input>` component for layout block is provided for user that want templating with Slack API style rather than HTML style.

## <a name="mrkdwn_component" id="mrkdwn_component"></a> [`<MrkDwn>`: Verbatim Block](https://api.slack.com/reference/block-kit/composition-objects#text) (Only for <Section> and <Context> blocks)
Copy link
Owner

@yhatt yhatt Dec 17, 2019

Choose a reason for hiding this comment

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

<Mrkdwn> is a part of text composition object and not layout blocks. We have to match a kind of element with Slack.

The documentation of <Mrkdwn> should place into "Composition objects" section in docs/block-elements.md.

As a same reason, moving src/block-kit/MrkDwn.tsx to src/block-kit/composition/Mrkdwn.tsx would be better. 👈Done.

src/block-kit/composition/Confirm.tsx Outdated Show resolved Hide resolved
src/block-kit/MrkDwn.tsx Outdated Show resolved Hide resolved
src/block-kit/Section.tsx Outdated Show resolved Hide resolved
test/block-kit/layout-blocks.tsx Outdated Show resolved Hide resolved
}

export const Mrkdwn: JSXSlack.FC<MrkdwnProps & {
children: JSXSlack.Children<BlockComponentProps>
Copy link
Owner

Choose a reason for hiding this comment

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

Duplicated definition.

import { BlockComponentProps } from '../Blocks'

interface MrkdwnProps extends BlockComponentProps {
children: JSXSlack.Children<BlockComponentProps>
Copy link
Owner

Choose a reason for hiding this comment

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

<Mrkdwn> component would not take block components as children. It would be better to take JSXSlack.Children<{}> as same as children in <Section> and <Context>.


interface MrkdwnProps extends BlockComponentProps {
children: JSXSlack.Children<BlockComponentProps>
verbatim: boolean
Copy link
Owner

Choose a reason for hiding this comment

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

FYI according to Slack API document, verbatim field is optional. Following this for user that wants to define JSON for Slack API exactly is good.

import html from '../../html'
import { BlockComponentProps } from '../Blocks'

interface MrkdwnProps extends BlockComponentProps {
Copy link
Owner

Choose a reason for hiding this comment

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

Don't extend BlockComponentProps. It includes blockId prop (and id alias prop) for layout blocks, and <Mrkdwn> composition object is not a part of that.

Copy link
Owner

@yhatt yhatt left a comment

Choose a reason for hiding this comment

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

About documentation...

@@ -633,6 +633,22 @@ As same as `<Input type="hidden">`, `submit` prop in `<Modal>` must not define w

It's exactly same as [`<Input>` component](#input-props), except `type` prop.

## <a name="mrkdwn_component" id="mrkdwn_component"></a> [`<Mrkdwn>`: Markdown Composition Component](https://api.slack.com/reference/block-kit/composition-objects#text)

Mrkdwn is a text composition component is used when its needed to have a Text object and explicitly set the `verbatim` property. Setting `verbatim` to false will tell Slack to auto-convert links, conversaion names, and certain mentions to be linkified and automatically parsed. If `verbatim` set to true Slack will skip any prepreprocessing.
Copy link
Owner

Choose a reason for hiding this comment

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

I can understand the use case well, but as our position, we cannot recommend using verbatim=false to enable automatic parsing because Slack is making clear a possibility of deprecating gradually in future.

We think verbatim attribute is like an escape hatch for the traditional Slack app. jsx-slack has already take verbatim=true as a default option even if not using <Mrkdwn> composition object. So we don't want to use this by users who will create new app with jsx-slack.

Thus, we should make clear these intents within this document.

Copy link
Owner

@yhatt yhatt left a comment

Choose a reason for hiding this comment

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

@javaPhil Thanks for your work! We want to release jsx-slack v1 with including <Mrkdwn> component. Could you resolve conflict and the reviewed documentation?

@@ -633,6 +633,24 @@ As same as `<Input type="hidden">`, `submit` prop in `<Modal>` must not define w

It's exactly same as [`<Input>` component](#input-props), except `type` prop.

## <a name="mrkdwn_component" id="mrkdwn_component"></a> [`<Mrkdwn>`: Markdown Composition Component](https://api.slack.com/reference/block-kit/composition-objects#text)
Copy link
Owner

Choose a reason for hiding this comment

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

Added documentation should be in a section of "Composition objects" (https://github.com/speee/jsx-slack/blob/master/docs/block-elements.md#composition-objects).

Please move it to below <Confirm> / right above ## Input components for modal, and demote each headings one level (## -> ###, ### -> ####).

@yhatt yhatt merged commit 897fc1b into yhatt:master Jan 10, 2020
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.

Allow verbatim={boolean} parameter
2 participants